List of usage examples for org.apache.poi.ss.usermodel CellStyle getFillPattern
FillPatternType getFillPattern();
From source file:org.pentaho.di.trans.steps.excelwriter.ExcelWriterStep_StyleFormatTest.java
License:Apache License
/** * Test applying Format and Style from cell (from a template) when writing fields * * @param fileType/*from www . j av a 2s.c o m*/ * @throws Exception */ private void testStyleFormat(String fileType) throws Exception { setupStepMock(fileType); createStepMeta(fileType); createStepData(fileType); step.init(stepMeta, stepData); // We do not run transformation or executing the whole step // instead we just execute ExcelWriterStepData.writeNextLine() to write to Excel workbook object // Values are written in A2:D2 and A3:D3 rows List<Object[]> rows = createRowData(); for (int i = 0; i < rows.size(); i++) { step.writeNextLine(rows.get(i)); } // Custom styles are loaded from G1 cell Row xlsRow = stepData.sheet.getRow(0); Cell baseCell = xlsRow.getCell(6); CellStyle baseCellStyle = baseCell.getCellStyle(); DataFormat format = stepData.wb.createDataFormat(); // Check style of the exported values in A3:D3 xlsRow = stepData.sheet.getRow(2); for (int i = 0; i < stepData.inputRowMeta.size(); i++) { Cell cell = xlsRow.getCell(i); CellStyle cellStyle = cell.getCellStyle(); if (i > 0) { assertEquals(cellStyle.getBorderRight(), baseCellStyle.getBorderRight()); assertEquals(cellStyle.getFillPattern(), baseCellStyle.getFillPattern()); } else { // cell A2/A3 has no custom style assertFalse(cellStyle.getBorderRight() == baseCellStyle.getBorderRight()); assertFalse(cellStyle.getFillPattern() == baseCellStyle.getFillPattern()); } if (i != 1) { assertEquals(format.getFormat(cellStyle.getDataFormat()), "0.00000"); } else { // cell B2/B3 use different format from the custom style assertEquals(format.getFormat(cellStyle.getDataFormat()), "##0,000.0"); } } }
From source file:uk.co.spudsoft.birt.emitters.excel.StyleManagerUtils.java
License:Open Source License
/** * Check whether a cell is empty and unformatted. * @param cell/*from w w w . j a va2s .c o m*/ * The cell to consider. * @return * true is the cell is empty and has no style or has no background fill. */ public static boolean cellIsEmpty(Cell cell) { if (cell.getCellType() != Cell.CELL_TYPE_BLANK) { return false; } CellStyle cellStyle = cell.getCellStyle(); if (cellStyle == null) { return true; } if (cellStyle.getFillPattern() == CellStyle.NO_FILL) { return true; } return false; }