pjfanning opened a new pull request, #1303: URL: https://github.com/apache/poi/pull/1303
Fixes https://bz.apache.org/bugzilla/show_bug.cgi?id=67646. Replaces #600, keeping only the change that is actually needed for the reported use case. ### Problem `SXSSFWorkbook(XSSFWorkbook)` documents "append rows to existing sheets" as a supported use case, and the writer already preserves the template's `<sheetData>` and appends the new rows after it. But `SXSSFSheet.getLastRowNum()` only looked at the rows in the streaming window, so on a freshly opened template sheet it returned `-1` and the natural `sheet.createRow(sheet.getLastRowNum() + 1)` failed with `Attempting to write a row[0] in the range [0,N] that is already written to disk`. The same thing happened after `flushRows()` emptied the window: `getLastRowNum()` went back to `-1` even though rows had been written. ### Fix `getLastRowNum()`, `getFirstRowNum()` and `getPhysicalNumberOfRows()` now consult the template sheet and the `SheetDataWriter` as well as the window (template rows always precede window rows, and flushed rows always precede unflushed ones, both enforced by `createRow`). Because `deriveDimension()` uses these methods, a template sheet with appended rows now gets a correct `<dimension>` covering both. That exposed two small pre-existing issues in `calculateLeftAndRightMostColumns()` from #65562: it was only called from the protected constructor, not the one `SXSSFWorkbook` actually uses, and it skipped rows whose first cell was not left of the running minimum (so a wider row further right did not extend the right bound). Both are fixed. ### Differences from #600 - `getRow()` keeps returning `SXSSFRow` and still only returns rows created in this sheet, as documented on the template constructor - no API change, no reading of template rows. - No changes to outline levels, exceptions, formatting, `.gitignore`s or the build version. - Tests: `TestSXSSFSheet.appendRowsToTemplate` (append with `getLastRowNum() + 1` in a window of 2, flush, write, read back and check rows, counts and dimension) and `TestSXSSFSheet.lastRowNumAfterFlush`. Full `poi-ooxml` suite passes locally apart from three auto-size column width assertions that depend on installed fonts and fail identically on trunk on this machine. 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
