List of usage examples for org.apache.poi.xssf.streaming SXSSFWorkbook createDataFormat
@Override
public DataFormat createDataFormat()
From source file:com.romeikat.datamessie.core.base.util.ExcelSheet.java
License:Open Source License
public ExcelSheet(final SXSSFWorkbook workbook, String sheetname) { // Sheet/* w w w . j a v a2 s . c o m*/ sheetname = normalizeSheetname(sheetname); sheet = workbook.createSheet(sheetname); // Date format final short dateFormat = workbook.createDataFormat().getFormat("dd.MM.yyyy"); dateFormatCellStyle = workbook.createCellStyle(); dateFormatCellStyle.setDataFormat(dateFormat); // Double number format final short doubleFormat = workbook.createDataFormat().getFormat("0.00"); doubleFormatCellStyle = workbook.createCellStyle(); doubleFormatCellStyle.setDataFormat(doubleFormat); // Indices currentRowIndex = 0; columnCursorIndex = 0; // Create first row currentRow = sheet.createRow(currentRowIndex); }
From source file:stroom.dashboard.server.download.ExcelTarget.java
License:Apache License
private void dateTime(final SXSSFWorkbook wb, final Cell cell, final Object value, final FormatSettings settings) { if (value instanceof Double) { final long ms = ((Double) value).longValue(); final Date date = new Date(ms); cell.setCellValue(date);// ww w. j a v a 2s. c o m cell.setCellType(Cell.CELL_TYPE_NUMERIC); String pattern = "dd/mm/yyyy hh:mm:ss"; if (settings != null && settings instanceof DateTimeFormatSettings) { final DateTimeFormatSettings dateTimeFormatSettings = (DateTimeFormatSettings) settings; if (dateTimeFormatSettings.getPattern() != null && dateTimeFormatSettings.getPattern().trim().length() > 0) { pattern = dateTimeFormatSettings.getPattern(); pattern = pattern.replaceAll("'", ""); pattern = pattern.replaceAll("\\.SSS", ""); } } final DataFormat df = wb.createDataFormat(); final CellStyle cs = wb.createCellStyle(); cs.setDataFormat(df.getFormat(pattern)); cell.setCellStyle(cs); } else { cell.setCellValue(getText(value)); } }
From source file:stroom.dashboard.server.download.ExcelTarget.java
License:Apache License
private void number(final SXSSFWorkbook wb, final Cell cell, final Object value, final FormatSettings settings) { if (value instanceof Double) { final double dbl = ((Double) value).doubleValue(); cell.setCellValue(dbl);//from ww w. j a va 2 s . c om cell.setCellType(Cell.CELL_TYPE_NUMERIC); if (settings != null && settings instanceof NumberFormatSettings) { final NumberFormatSettings numberFormatSettings = (NumberFormatSettings) settings; final StringBuilder sb = new StringBuilder(); if (Boolean.TRUE.equals(numberFormatSettings.getUseSeparator())) { sb.append("#,##0"); } else { sb.append("#"); } if (numberFormatSettings.getDecimalPlaces() != null && numberFormatSettings.getDecimalPlaces() > 0) { sb.append("."); for (int i = 0; i < numberFormatSettings.getDecimalPlaces(); i++) { sb.append("0"); } } final String pattern = sb.toString(); final DataFormat df = wb.createDataFormat(); final CellStyle cs = wb.createCellStyle(); cs.setDataFormat(df.getFormat(pattern)); cell.setCellStyle(cs); } } else { cell.setCellValue(getText(value)); } }