List of usage examples for org.apache.poi.xssf.usermodel XSSFCellStyle setDataFormat
public void setDataFormat(int fmt)
From source file:se.minstrel.tools.xssfbuilder.style.impl.StyleBuilderImpl.java
License:Open Source License
private XSSFCellStyle buildStyle() { XSSFWorkbook wb = support.getWorkbook(); XSSFFont font = wb.createFont();//from w ww. j a va2 s . com font.setFontName(style.getFont()); font.setFontHeightInPoints(style.getFontSize()); font.setBold(style.isBold()); font.setItalic(style.isItalics()); if (style.getFgColor() != null) { font.setColor(new XSSFColor(style.getFgColor())); } XSSFCellStyle cs = support.getWorkbook().createCellStyle(); cs.setFont(font); if (style.getBgColor() != null) { cs.setFillForegroundColor(new XSSFColor(style.getBgColor())); cs.setFillPattern(FillPatternType.SOLID_FOREGROUND); } if (style.getFormat() != null) { cs.setDataFormat(support.getDataFormat().getFormat(style.getFormat())); } // style.getBgColor(); // style.getFgColor(); // style.isBold(); // style.isItalics(); return cs; }
From source file:uk.gov.ofwat.fountain.api.report.POIReportWriter.java
License:Open Source License
private XSSFCellStyle getInputDataNumericStyle(DataFormat format, DataDto dataDto) { short formatIndex = cellFormat(format, dataDto); if (inputDataNumericStyleMap.containsKey(formatIndex)) { return inputDataNumericStyleMap.get(formatIndex); }/* w ww .ja v a 2s . c om*/ XSSFCellStyle style = workBook.createCellStyle(); style.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND); style.setFillForegroundColor(lightYellow); style.setDataFormat(formatIndex); inputDataNumericStyleMap.put(formatIndex, style); return style; }
From source file:uk.gov.ofwat.fountain.api.report.POIReportWriter.java
License:Open Source License
private XSSFCellStyle getCalcDataNumericStyle(DataFormat format, DataDto dataDto) { short formatIndex = cellFormat(format, dataDto); if (calcDataNumericStyleMap.containsKey(formatIndex)) { return calcDataNumericStyleMap.get(formatIndex); }/* w w w . j a v a 2 s . c o m*/ XSSFCellStyle style = workBook.createCellStyle(); style.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND); style.setFillForegroundColor(lightBlue); style.setDataFormat(formatIndex); calcDataNumericStyleMap.put(formatIndex, style); return style; }
From source file:uk.gov.ofwat.fountain.api.table.POITableRenderer.java
License:Open Source License
private XSSFCellStyle getInputDataNumericStyle(DataFormat format, DataDto dataDto) { short formatIndex = cellFormat(format, dataDto); if (inputDataNumericStyleMap.containsKey(formatIndex)) { return inputDataNumericStyleMap.get(formatIndex); }/* www . ja va 2 s .c om*/ XSSFCellStyle style = workBook.createCellStyle(); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFillForegroundColor(lightYellow); style.setDataFormat(formatIndex); inputDataNumericStyleMap.put(formatIndex, style); return style; }
From source file:uk.gov.ofwat.fountain.api.table.POITableRenderer.java
License:Open Source License
private XSSFCellStyle getCopyCellDataNumericStyle(DataFormat format, DataDto dataDto) { short formatIndex = cellFormat(format, dataDto); if (copyCellDataNumericStyleMap.containsKey(formatIndex)) { return copyCellDataNumericStyleMap.get(formatIndex); }/*from ww w . jav a 2s . co m*/ XSSFCellStyle style = workBook.createCellStyle(); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFillForegroundColor(pink); style.setDataFormat(formatIndex); copyCellDataNumericStyleMap.put(formatIndex, style); return style; }
From source file:uk.gov.ofwat.fountain.api.table.POITableRenderer.java
License:Open Source License
private XSSFCellStyle getCalcDataNumericStyle(DataFormat format, DataDto dataDto) { short formatIndex = cellFormat(format, dataDto); if (calcDataNumericStyleMap.containsKey(formatIndex)) { return calcDataNumericStyleMap.get(formatIndex); }//from www . j ava2 s .co m XSSFCellStyle style = workBook.createCellStyle(); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFillForegroundColor(lightBlue); style.setDataFormat(formatIndex); calcDataNumericStyleMap.put(formatIndex, style); return style; }
From source file:uk.gov.ofwat.RefTest.java
License:Open Source License
public void writeXLS() throws IOException { XSSFWorkbook wb = new XSSFWorkbook(); CreationHelper creationHelper = wb.getCreationHelper(); // create a new sheet Sheet s = wb.createSheet();//from ww w . j av a 2 s . c o m // declare a row object reference Row r = null; // declare a cell object reference Cell c = null; // create 2 cell styles XSSFCellStyle cs = wb.createCellStyle(); XSSFCellStyle cs2 = wb.createCellStyle(); DataFormat df = wb.createDataFormat(); // create 2 fonts objects Font f = wb.createFont(); Font f2 = wb.createFont(); // Set font 1 to 12 point type, blue and bold f.setFontHeightInPoints((short) 12); f.setColor(IndexedColors.RED.getIndex()); f.setBoldweight(Font.BOLDWEIGHT_BOLD); // Set font 2 to 10 point type, red and bold f2.setFontHeightInPoints((short) 10); f2.setColor(IndexedColors.RED.getIndex()); f2.setBoldweight(Font.BOLDWEIGHT_BOLD); // Set cell style and formatting cs.setFont(f); cs.setDataFormat(df.getFormat("#,##0.0")); // Set the other cell style and formatting cs2.setBorderBottom(cs2.BORDER_THIN); cs2.setDataFormat((short) BuiltinFormats.getBuiltinFormat("text")); cs2.setFont(f2); // Define a few rows for (int rownum = 0; rownum < 30; rownum++) { r = s.createRow(rownum); for (int cellnum = 0; cellnum < 10; cellnum += 2) { c = r.createCell(cellnum); Cell c2 = r.createCell(cellnum + 1); c.setCellValue((double) rownum + (cellnum / 10)); c2.setCellValue(creationHelper.createRichTextString("Hello! " + cellnum)); } } File file = new File("d:\\out.xls"); FileOutputStream fos = new FileOutputStream(file); wb.write(fos); // fos.write(wb.getBytes()); // fos.flush(); // fos.close(); }