Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -341,22 +341,14 @@ private CellStyle createOrRetrieveCellStyle(HorizontalAlignment alignment, Cell

@SuppressWarnings("unchecked")
private void buildCell(Object value, Cell cell, Column<T> column, T item) {
ValueProvider<T,String> provider = null;
provider = (ValueProvider<T, String>) ComponentUtil.getData(column, GridExporter.COLUMN_EXCEL_FORMAT_DATA_PROVIDER);
String excelFormat;
Map<String,CellStyle> cellStyles = (Map<String, CellStyle>) 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<T,String> provider = (ValueProvider<T, String>) ComponentUtil.getData(column, GridExporter.COLUMN_EXCEL_FORMAT_DATA_PROVIDER);
Map<String, CellStyle> cellStyles = getCellStyles(column);
String excelFormat = getExcelFormat(column, item, provider);
if (value == null) {
PoiHelper.setBlank(cell);
if(excelFormat != null) {
applyExcelFormat(cell, excelFormat, cellStyles);
}
} else if (value instanceof Number) {
excelFormat = (excelFormat!=null)?excelFormat:"0";
cell.setCellValue(((Number) value).doubleValue());
Expand All @@ -375,6 +367,27 @@ private void buildCell(Object value, Cell cell, Column<T> column, T item) {
}
}

private String getExcelFormat(Column<T> column, T item, ValueProvider<T, String> 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<String, CellStyle> getCellStyles(Column<T> column) {
Map<String,CellStyle> cellStyles = (Map<String, CellStyle>) 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<String, CellStyle> cellStyles) {
DataFormat format = cell.getSheet().getWorkbook().createDataFormat();
if (excelFormat!=null && cellStyles.get(excelFormat)==null) {
Expand Down
Loading