Bug 60895 - CellUtil.setCellStyleProperties(), corrupts conditional Formatting
Summary: CellUtil.setCellStyleProperties(), corrupts conditional Formatting
Alias: None
Product: POI
Classification: Unclassified
Component: SS Common (show other bugs)
Version: 3.15-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2017-03-21 10:52 UTC by dollinger.florian
Modified: 2018-12-30 16:43 UTC (History)
1 user (show)


Note You need to log in before you can comment on or make changes to this bug.
Description dollinger.florian 2017-03-21 10:52:53 UTC
Given a XSSF Sheet.
Then the following code leads to a out.xlsx in which conditional formatting does not work for the created cell A1 (at least not in Excel):

XSSFWorkbook wbOut = new XSSFWorkbook("C:/out.xlsx");
XSSFWorkbook wbIn = new XSSFWorkbook("C:/in.xlsx");

XSSFSheet srcSheet = wbOut.getSheetAt(0);
XSSFSheet dstSheet = wbIn.getSheetAt(0);

XSSFRow srcRow = srcSheet.getRow(0);
XSSFRow dstRow = dstSheet.getRow(0);

XSSFCell oldCell = srcRow.getCell(0);
XSSFCell newCell = dstRow.createCell(0);

Map<String, Object> props = new HashMap<>();
props.put(CellUtil.ROTATION, oldCell.getCellStyle().getRotation());
CellUtil.setCellStyleProperties(newCell, props);

The problem is similar to the one in bug 60845, setCellStyleProperties() creates new fills instead of using the already existing ones:

That means, the corresponding Fill for A1 is now:

    <fgColor indexed="64"/>
    <bgColor indexed="64"/>

instead of the default one:

  <patternFill patternType="none"/>


A possible solution could be:
1) handle "indexed="64" as "none"/null, since 64 is the value for AUTOMATIC/NONE in the getFormatProperties/setFormatProperties functions
2) create a new derived CellUtil for XSSF, since many other things (like XSSFColors) don't work too
Comment 1 Dominik Stadler 2018-12-30 16:43:19 UTC
Bug 60845 is resolved now. Does this also fix this issue?