XSSFDataFormat df = workBook.createDataFormat(); cs.setDataFormat(df.getFormat("d-mmm-yy")); // Get / Create our cell XSSFRow row = sheet.createRow(2); XSSFCell cell = row.createCell(3); // Set it to be a date Calendar c = Calendar.getInstance(); c.set(2012,3-1,18); // Don't forget months are 0 based on Calendar cell.setCellValue( c.getTime() ); // Style it as a date cell.setCellStyle(cs);
/** * Get the contents of the format string, by looking up * the StylesSource * * @return the number format string */ @Override public String getDataFormatString() { int idx = getDataFormat(); return new XSSFDataFormat(_stylesSource).getFormat((short)idx); }
(new XSSFDataFormat(_stylesSource)).getFormat(fmt) );
@Override public void reset(XSSFWorkbook workbook) { style = workbook.createCellStyle(); style.setDataFormat(workbook.getCreationHelper() .createDataFormat().getFormat(formatString)); }
XSSFDataFormat df = wb.createDataFormat(); italicStyle.setDataFormat(df.getFormat("##0"));
XSSFCellStyle cellStyle = workBook.createCellStyle(); XSSFDataFormat format = workBook.createDataFormat(); cellStyle.setDataFormat(format.getFormat("m/d/yy h:mm")); dataCell.setCellStyle(cellStyle); // Set Cell Type not really needed, the setCellValue does it dataCell.setCellType(Cell.CELL_TYPE_NUMERIC); // Set a date value (2012-06-05 08:50) dataCell.setCellValue(new Date(1338878999635));
/** * Get the contents of the format string, by looking up * the StylesSource * * @return the number format string */ @Override public String getDataFormatString() { int idx = getDataFormat(); return new XSSFDataFormat(_stylesSource).getFormat((short)idx); }
XSSFCellStyle my_style = (XSSFCellStyle) wb.createCellStyle(); XSSFFont my_font=(XSSFFont) wb.createFont(); my_font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD); my_style.setFont(my_font); XSSFDataFormat df =(XSSFDataFormat) wb.createDataFormat(); my_style.setDataFormat(df.getFormat("#,##0"));
/** * Get the contents of the format string, by looking up * the StylesSource * * @return the number format string */ public String getDataFormatString() { int idx = getDataFormat(); return new XSSFDataFormat(_stylesSource).getFormat((short)idx); }
Cell new_cell = row.createCell(index_column_found); XSSFCellStyle cs = wBook.createCellStyle(); XSSFDataFormat df = wBook.createDataFormat(); cs.setDataFormat(df.getFormat(cell_custom_format)); new_cell.setCellStyle(cs);
private CellStyle getCellDataFormat(int scale, XSSFWorkbook workbook) { CellStyle style = workbook.createCellStyle(); if(scale > 0){ String dataFormat = "0."; for(int i = 0; i < scale; i++){ dataFormat = dataFormat+"0"; } style.setDataFormat(workbook.createDataFormat().getFormat(dataFormat)); } return style; }
public void setStyle(String name, String format) { getStyle(name).setDataFormat(workbook.getCreationHelper().createDataFormat().getFormat(format)); }
@Override public void transform(XSSFCellStyle cellStyle) { XSSFDataFormat format = sheet.getWorkbook().getCreationHelper().createDataFormat(); cellStyle.setAlignment(alignment.excelAlignment(date, cellStyle)); cellStyle.setDataFormat(format.getFormat(formatProvider.getExcelDateFormat(locale.getCountry()))); } }
@Override public void transform(XSSFCellStyle cellStyle) { XSSFDataFormat format = sheet.getWorkbook().getCreationHelper().createDataFormat(); cellStyle.setAlignment(alignment.excelAlignment(timestamp, cellStyle)); cellStyle.setDataFormat(format.getFormat(formatProvider.getExcelDateTimeFormat(locale.getCountry()))); } }
@Override public void transform(XSSFCellStyle cellStyle) { XSSFDataFormat format = sheet.getWorkbook().getCreationHelper().createDataFormat(); cellStyle.setAlignment(alignment.excelAlignment(money, cellStyle)); cellStyle.setDataFormat(format.getFormat(getExcelCurrencyFormat(money.getCurrencyCd()))); } }
@Override public void prepareColumn(TableModel tableModel, XSSFSheet sheet, int col) { XSSFWorkbook wb = sheet.getWorkbook(); XSSFDataFormat df = wb.createDataFormat(); cellStyle = wb.createCellStyle(); XSSFFont f = wb.createFont(); f.setFontHeightInPoints((short) 12); f.setColor(IndexedColors.BLACK.getIndex()); cellStyle.setFont(f); cellStyle.setDataFormat(df.getFormat("m/d/yy")); }
@Override public void prepareColumn(TableModel tableModel, XSSFSheet sheet, int col) { XSSFWorkbook wb = sheet.getWorkbook(); XSSFDataFormat df = wb.createDataFormat(); cellStyle = wb.createCellStyle(); XSSFFont f = wb.createFont(); f.setFontHeightInPoints((short) 12); f.setColor(IndexedColors.BLACK.getIndex()); cellStyle.setFont(f); cellStyle.setDataFormat(df.getFormat("text")); }
@Override public void prepareColumn(TableModel tableModel, XSSFSheet sheet, int col) { XSSFWorkbook wb = sheet.getWorkbook(); XSSFDataFormat df = wb.createDataFormat(); cellStyle = wb.createCellStyle(); XSSFFont f = wb.createFont(); f.setFontHeightInPoints((short) 12); f.setColor(IndexedColors.BLACK.getIndex()); cellStyle.setFont(f); cellStyle.setDataFormat(df.getFormat("text")); }
@Override public void prepareColumn(TableModel tableModel, XSSFSheet sheet, int col) { XSSFWorkbook wb = sheet.getWorkbook(); XSSFDataFormat df = wb.createDataFormat(); cellStyle = wb.createCellStyle(); XSSFFont f = wb.createFont(); f.setFontHeightInPoints((short) 12); f.setColor(IndexedColors.BLACK.getIndex()); cellStyle.setFont(f); cellStyle.setDataFormat(df.getFormat("m/d/yy h:mm")); }
protected void createExcelHeader(XSSFWorkbook workbook, XSSFSheet tableSheet) throws Exception { XSSFFont f = workbook.createFont(); f.setFontHeightInPoints((short) 12); f.setColor(IndexedColors.BLACK.getIndex()); XSSFDataFormat df = workbook.createDataFormat(); XSSFCellStyle cs = workbook.createCellStyle(); cs.setFont(f); cs.setDataFormat(df.getFormat("text")); cs.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); cs.setFillPattern(FillPatternType.SOLID_FOREGROUND); cs.setWrapText(true); XSSFCreationHelper createHelper = workbook.getCreationHelper(); XSSFRow rh = tableSheet.createRow(0); for (int i = 0; i < table.getColumnCount(); i++) { XSSFCell c1 = rh.createCell(i); c1.setCellStyle(cs); c1.setCellValue(createHelper.createRichTextString(table.getColumnName(i))); c1.setCellType(XSSFCell.CELL_TYPE_STRING); } }