|Summary:||CellStyles propagate unexpectedly and incorrectly|
|Product:||POI||Reporter:||Marco Barigazzi <marco.barigazzi>|
|Component:||XSSF||Assignee:||POI Developers List <dev>|
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(); styleRight.setAlignment(HorizontalAlignment.RIGHT); styleLeft.setAlignment(HorizontalAlignment.LEFT); 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.