private void replaceMonthDatesInHeaderRow(Calendar startDate, ExportRow row) { // Adding month columns Calendar startDateColumn = Calendar.getInstance(); startDateColumn.setTime(startDate.getTime()); SimpleDateFormat sdf = new SimpleDateFormat("MMMMM yyyy"); int i = 30; for (PosCol month : monthCols) { ExportCell cell = row.getCell(i); cell.setValue(sdf.format(startDateColumn.getTime())); startDateColumn.add(Calendar.MONTH, 1); i++; } }
public ExportRow addRow(final Object... values) { final ExportRow row = addRow(); row.setValues(values); return row; }
public ExportRow addRow() { final Row poiRow = poiSheet.createRow(rowCounter); final ExportRow row = new ExportRow(contentProvider, this, poiRow, rowCounter++); this.rows.add(row); return row; }
@Override public MyContentProvider updateRowStyle(final ExportRow row) { for (final ExportCell cell : row.getCells()) { final CellFormat format = cell.ensureAndGetCellFormat(); format.setFillForegroundColor(HSSFColor.WHITE.index); switch (row.getRowNum()) { case 0: format.setFont(FONT_NORMAL_BOLD); // alignment = CellStyle.ALIGN_CENTER; break; default: format.setFont(FONT_NORMAL); if (row.getRowNum() % 2 == 0) { format.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); } break; } } return this; }
public void setValuesFrom(int fromCol, final Object... values) { for (final Object value : values) { addCell(fromCol++, value); } }
/** * Gets only added cells, if the requested cell does not exist, null will be returned. * * @param col */ public ExportCell getCell(final int col) { return getCells()[col]; }
public ExportCell addCell(final int col, final Object value, final String property) { final Cell poiCell = poiRow.createCell(col); final ExportCell cell = addPoiCell(col, poiCell); cell.setValue(value, property); return cell; }
public ExportRow addRow(final Object rowBean, final int startCol) { final ExportRow row = addRow(); row.fillBean(rowBean, propertyNames, 0); return row; }
/** * Set auto-filter for the whole first row. Must be called after adding the first row with all heading cells. * * @return this for chaining. */ public ExportSheet setAutoFilter() { final int headingRow = 0; final ExportRow row = getRow(headingRow); final int lastCol = row.getMaxCol(); final CellRangeAddress range = new CellRangeAddress(headingRow, headingRow, 0, lastCol); getPoiSheet().setAutoFilter(range); return this; }
for (final ExportCell cell : row.getCells()) { final CellFormat format = cell.ensureAndGetCellFormat(); format.setFillForegroundColor(HSSFColor.WHITE.index); switch (row.getRowNum()) { default: format.setFont(FONT_NORMAL); if (row.getRowNum() % 2 == 0) { format.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
public ExportCell addCell(final int col, final Object value) { return addCell(col, value, null); }
/** * If the sheet has not its own StyleProvider then the given StyleProvider will be used (if not null). * * @param contentProvider Can be null. */ public void updateStyles(final ContentProvider contentProvider) { ContentProvider cp = this.contentProvider; if (cp == null) { cp = contentProvider; } if (cp == null) { return; } cp.updateRowStyle(this); for (final ExportCell cell : getCells()) { if (cell != null) { cp.updateCellStyle(cell); } } }
public ExportRow(final ContentProvider contentProvider, final ExportSheet sheet, final Row poiRow, final int rowNum) { this.contentProvider = contentProvider; this.sheet = sheet; this.poiRow = poiRow; this.rowNum = rowNum; cellMap = new HashMap<Integer, ExportCell>(); if (poiRow.getLastCellNum() > 0) { // poiRow does already exists. for (int i = poiRow.getFirstCellNum(); i < poiRow.getLastCellNum(); i++) { final Cell poiCell = poiRow.getCell(i); if (poiCell != null) { addPoiCell(i, poiCell); } } } }
@Override public MyContentProvider updateRowStyle(final ExportRow row) { for (final ExportCell cell : row.getCells()) { final CellFormat format = cell.ensureAndGetCellFormat(); format.setFillForegroundColor(HSSFColor.WHITE.index); switch (row.getRowNum()) { case 0: format.setFont(FONT_HEADER); break; case 1: format.setFont(FONT_NORMAL_BOLD); // alignment = CellStyle.ALIGN_CENTER; break; default: format.setFont(FONT_NORMAL); if (row.getRowNum() % 2 == 0) { format.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); } break; } } return this; }
public static void main(String... args) throws IOException { final ExportWorkbook workbook = new ExportWorkbook(); ExportSheet sheet = workbook.addSheet("Data types"); sheet.getContentProvider().setColWidths(20, 20); sheet.addRow().setValues("Type", "result"); sheet.addRow().setValues("String", "This is a text."); sheet.addRow().setValues("int", 1234); sheet.addRow().setValues("BigDecimal", new BigDecimal("1042.3873")); Date date = new Date(); sheet.addRow().setValues("Date", date); sheet.addRow().setValues("SQL-Date", new java.sql.Date(date.getTime())); sheet.addRow().setValues("Timestamp", new Timestamp(date.getTime())); sheet = workbook.addSheet("Own data types"); sheet.getContentProvider().setColWidths(20, 20).putFormat(Currency.class, "#,##0.00;[Red]-#,##0.00"); sheet.addRow().setValues("Type", "result"); sheet.addRow().setValues("Currency", new Currency("1023.873").getValue()); sheet.addRow().setValues("Currency", new Currency("-10").getValue()); final File file = new File("target/test-excel.xls"); log.info("Writing Excel test sheet to work directory: " + file.getAbsolutePath()); workbook.write(new FileOutputStream(file)); } }
private void fillIstSum(ExportSheet sheet, Map<PosCol, BigDecimal> istSumMap) { ExportRow istRow = sheet.getRow(6); int i = 30; for (PosCol monthCol : istSumMap.keySet()) { istRow.getCell(i).setValue(istSumMap.get(monthCol)); i++; } }
public ExportCell addCell(final int col) { return addCell(col, null, null); }