diff --git a/src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelStreamResourceWriter.java b/src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelStreamResourceWriter.java index 9ecfb10..6dd1598 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelStreamResourceWriter.java +++ b/src/main/java/com/flowingcode/vaadin/addons/gridexporter/ExcelStreamResourceWriter.java @@ -341,20 +341,9 @@ private CellStyle createOrRetrieveCellStyle(HorizontalAlignment alignment, Cell @SuppressWarnings("unchecked") private void buildCell(Object value, Cell cell, Column column, T item) { - ValueProvider provider = null; - provider = (ValueProvider) ComponentUtil.getData(column, GridExporter.COLUMN_EXCEL_FORMAT_DATA_PROVIDER); - String excelFormat; - Map cellStyles = (Map) ComponentUtil.getData(column, COLUMN_CELLSTYLE_MAP); - if (cellStyles==null) { - cellStyles = new HashMap<>(); - ComponentUtil.setData(column, COLUMN_CELLSTYLE_MAP, cellStyles); - } - if (provider!=null) { - excelFormat = provider.apply(item); - } else { - excelFormat = - (String) ComponentUtil.getData(column, GridExporter.COLUMN_EXCEL_FORMAT_DATA); - } + ValueProvider provider = (ValueProvider) ComponentUtil.getData(column, GridExporter.COLUMN_EXCEL_FORMAT_DATA_PROVIDER); + Map cellStyles = getCellStyles(column); + String excelFormat = getExcelFormat(column, item, provider); if (value == null) { PoiHelper.setBlank(cell); if(excelFormat != null) { @@ -378,6 +367,27 @@ private void buildCell(Object value, Cell cell, Column column, T item) { } } + private String getExcelFormat(Column column, T item, ValueProvider provider) { + String excelFormat; + if (provider!=null) { + excelFormat = provider.apply(item); + } else { + excelFormat = + (String) ComponentUtil.getData(column, GridExporter.COLUMN_EXCEL_FORMAT_DATA); + } + return excelFormat; + } + + @SuppressWarnings("unchecked") + private Map getCellStyles(Column column) { + Map cellStyles = (Map) ComponentUtil.getData(column, COLUMN_CELLSTYLE_MAP); + if (cellStyles==null) { + cellStyles = new HashMap<>(); + ComponentUtil.setData(column, COLUMN_CELLSTYLE_MAP, cellStyles); + } + return cellStyles; + } + private void applyExcelFormat(Cell cell, String excelFormat, Map cellStyles) { DataFormat format = cell.getSheet().getWorkbook().createDataFormat(); if (excelFormat!=null && cellStyles.get(excelFormat)==null) {