Bug 64494 - CellStyles propagate unexpectedly and incorrectly
Summary: CellStyles propagate unexpectedly and incorrectly
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2020-06-03 12:39 UTC by Marco Barigazzi
Modified: 2021-01-03 12:02 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Marco Barigazzi 2020-06-03 12:39:31 UTC
Hello, in the context of XSSF CellStyles this happens. If I write this very simple code:

XSSFCellStyle styleRight = workbook.createCellStyle();
XSSFCellStyle styleLeft = workbook.createCellStyle();

The cells that have their style set to styleLeft will also, incorrectly, be aligned to the right. 

If there is any other command that acts on either one of these styles, say for example a setFont or setDataFormat, at any other point in the code, the cells that have their style set to styleLeft will correctly be aligned to the left.

If BOTH styles have a, say, setFont applied to them, and the font put as argument is the same object for both styles, the alignment will break again and the supposedly left-aligned cells will align right (this doesn't happen if two identical objects are set as the setFont arguments in either style).

If the order in which the objects are created flips (so styleLeft is created before styleRight), so does the alignment (both will be aligned left). This applies also for >2 styles, the first style created will propagate to all the following ones.
Comment 1 Dominik Stadler 2021-01-03 12:02:26 UTC
It seems there is an additional "applyAlignment" boolean that is currently not handled by Apache POI.

This should be fixed on latest trunk via r1885059 by setting this and also checking it's value for getters, you should be able to verify this via the next nightly build.