You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by "fakhrulsojib (via GitHub)" <gi...@apache.org> on 2026/03/12 08:46:44 UTC
[PR] Fix Row.setRowStyle() not propagating styles to cells in XSSFCell and SXSSFCell [poi]
fakhrulsojib opened a new pull request, #1031:
URL: https://github.com/apache/poi/pull/1031
## Summary
`Row.setRowStyle()` does not propagate styles to cells via `Cell.getCellStyle()`. This is a regression from POI 3.17 affecting both [XSSFCell](cci:2://file:///home/fakhrulislam/Documents/personal_project/poi/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFCell.java:75:0-1257:1) and [SXSSFCell](cci:2://file:///home/fakhrulislam/Documents/personal_project/poi/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFCell.java:47:0-1343:1).
**Bugzilla:** https://bz.apache.org/bugzilla/show_bug.cgi?id=69973
**Related:** Bug 66679, Bug 56011
## Root Cause
Three issues in `XSSFCell.getCellStyle()` (and mirrored in [SXSSFCell](cci:2://file:///home/fakhrulislam/Documents/personal_project/poi/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFCell.java:47:0-1343:1)):
1. Fallback chain is `explicit → column` — row is never checked
2. [getDefaultCellStyleFromColumn()](cci:1://file:///home/fakhrulislam/Documents/personal_project/poi/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFCell.java:612:4-621:5) uses `XSSFSheet.getColumnStyle()` which converts "no column style" (-1) into the default style (0), so it never returns null — blocking any further fallback
3. [applyDefaultCellStyleIfNecessary()](cci:1://file:///home/fakhrulislam/Documents/personal_project/poi/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFCell.java:613:4-617:5) (called during `workbook.write()`) only checks column style
## Changes
**[XSSFCell.java](cci:7://file:///home/fakhrulislam/Documents/personal_project/poi/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFCell.java:0:0-0:0) / [SXSSFCell.java](cci:7://file:///home/fakhrulislam/Documents/personal_project/poi/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFCell.java:0:0-0:0):**
- [getCellStyle()](cci:1://file:///home/fakhrulislam/Documents/personal_project/poi/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFCell.java:585:4-610:5) — new 4-step fallback: explicit → column → row → default(0)
- [getDefaultCellStyleFromColumn()](cci:1://file:///home/fakhrulislam/Documents/personal_project/poi/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFCell.java:612:4-621:5) — use `ColumnHelper.getColDefaultStyle()` directly, return null when no explicit column style
- [getDefaultCellStyleFromRow()](cci:1://file:///home/fakhrulislam/Documents/personal_project/poi/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFCell.java:623:4-629:5) — new helper using `row.isFormatted()` / `row.getRowStyle()`
- [applyDefaultCellStyleIfNecessary()](cci:1://file:///home/fakhrulislam/Documents/personal_project/poi/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFCell.java:613:4-617:5) — simplified to reuse [getCellStyle()](cci:1://file:///home/fakhrulislam/Documents/personal_project/poi/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFCell.java:585:4-610:5) fallback chain
**[TestXSSFRow.java](cci:7://file:///home/fakhrulislam/Documents/personal_project/poi/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFRow.java:0:0-0:0) / [TestSXSSFRow.java](cci:7://file:///home/fakhrulislam/Documents/personal_project/poi/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFRow.java:0:0-0:0):**
- [testSetRowStylePropagatedToCells](cci:1://file:///home/fakhrulislam/Documents/personal_project/poi/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFRow.java:75:4-116:5) — verifies in-memory inheritance + explicit style not overridden
- [testSetRowStylePropagatedAfterWrite](cci:1://file:///home/fakhrulislam/Documents/personal_project/poi/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFRow.java:118:4-154:5) — verifies style persistence through write/read-back cycle
## Test Results
| Suite | Tests | Result |
|---|---|---|
| TestXSSFRow | 28 (26 + 2 new) | ✅ |
| TestXSSFCell | 85 | ✅ No regressions |
| TestSXSSFRow | 16 (14 + 2 new) | ✅ |
| TestSXSSFCell | 56 | ✅ No regressions |
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [PR] Fix Row.setRowStyle() not propagating styles to cells in XSSFCell and SXSSFCell [poi]
Posted by "fakhrulsojib (via GitHub)" <gi...@apache.org>.
fakhrulsojib commented on PR #1031:
URL: https://github.com/apache/poi/pull/1031#issuecomment-4047358921
@pjfanning ,
My bad — forgot to build the full project before pushing.
Fixed now. Also updated `HSSFCell` to match the pattern used by the others.
Sorry for the two force pushes too. Bad habit :(
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [PR] Fix Row.setRowStyle() not propagating styles to cells in XSSFCell and SXSSFCell [poi]
Posted by "fakhrulsojib (via GitHub)" <gi...@apache.org>.
fakhrulsojib commented on code in PR #1031:
URL: https://github.com/apache/poi/pull/1031#discussion_r2925037151
##########
poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFRow.java:
##########
@@ -20,14 +20,21 @@
package org.apache.poi.xssf.streaming;
import org.apache.poi.ss.tests.usermodel.BaseTestXRow;
+import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.xssf.SXSSFITestDataProvider;
+import org.apache.poi.xssf.usermodel.XSSFCell;
+import org.apache.poi.xssf.usermodel.XSSFCellStyle;
+import org.apache.poi.xssf.usermodel.XSSFFont;
+import org.apache.poi.xssf.usermodel.XSSFRow;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.io.IOException;
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.*;
Review Comment:
Updated to use explicit imports.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [PR] Fix Row.setRowStyle() not propagating styles to cells in XSSFCell and SXSSFCell [poi]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning merged PR #1031:
URL: https://github.com/apache/poi/pull/1031
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [PR] Fix Row.setRowStyle() not propagating styles to cells in XSSFCell and SXSSFCell [poi]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on PR #1031:
URL: https://github.com/apache/poi/pull/1031#issuecomment-4046012206
@fakhrulsojib don't squash your commits. I can squash them when the PR is merged.
The advantage to my approach is that I can see your individual commits and don't have to re-read the entire PR changeset ever time you make a small change.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [PR] Fix Row.setRowStyle() not propagating styles to cells in XSSFCell and SXSSFCell [poi]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on PR #1031:
URL: https://github.com/apache/poi/pull/1031#issuecomment-4046460551
One test is broken.
```
Test defaultRowStyle() FAILED
org.opentest4j.AssertionFailedError: style should match ==> expected: <21> but was: <15>
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [PR] Fix Row.setRowStyle() not propagating styles to cells in XSSFCell and SXSSFCell [poi]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #1031:
URL: https://github.com/apache/poi/pull/1031#discussion_r2924027696
##########
poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFRow.java:
##########
@@ -20,14 +20,21 @@
package org.apache.poi.xssf.streaming;
import org.apache.poi.ss.tests.usermodel.BaseTestXRow;
+import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.xssf.SXSSFITestDataProvider;
+import org.apache.poi.xssf.usermodel.XSSFCell;
+import org.apache.poi.xssf.usermodel.XSSFCellStyle;
+import org.apache.poi.xssf.usermodel.XSSFFont;
+import org.apache.poi.xssf.usermodel.XSSFRow;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.io.IOException;
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.*;
Review Comment:
use explicit imports, not wildcards
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [PR] Fix Row.setRowStyle() not propagating styles to cells in XSSFCell and SXSSFCell [poi]
Posted by "fakhrulsojib (via GitHub)" <gi...@apache.org>.
fakhrulsojib commented on code in PR #1031:
URL: https://github.com/apache/poi/pull/1031#discussion_r2925038680
##########
poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFRow.java:
##########
@@ -500,4 +500,86 @@ private void writeToFile(Workbook wb) throws IOException {
wb.write(fileOut);
}
}
+
+ @Test
+ void testSetRowStylePropagatedToCells() throws IOException {
Review Comment:
Refactored to use try-with-resource
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [PR] Fix Row.setRowStyle() not propagating styles to cells in XSSFCell and SXSSFCell [poi]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #1031:
URL: https://github.com/apache/poi/pull/1031#discussion_r2924037082
##########
poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFRow.java:
##########
@@ -500,4 +500,86 @@ private void writeToFile(Workbook wb) throws IOException {
wb.write(fileOut);
}
}
+
+ @Test
+ void testSetRowStylePropagatedToCells() throws IOException {
Review Comment:
keep the private methods at the bottom - move this up to where the tests are
use try with resources to close the workbook - there are some tests in this class that do that
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [PR] Fix Row.setRowStyle() not propagating styles to cells in XSSFCell and SXSSFCell [poi]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on PR #1031:
URL: https://github.com/apache/poi/pull/1031#issuecomment-4198526452
thanks - merged
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org