Skip to content

Streaming copy with SXSSF

PJ Fanning edited this page Aug 3, 2022 · 3 revisions

excel-streaming-reader supports reading xlsx files. POI's SXSSFWorkbook can be used to write xlsx files in a streaming way.

If you need to modify an existing xlsx file, it is easiest to use POI's in-memory XSSFWorkbook.

If you don't have enough memory available, then reading using excel-streaming-reader and writing using SXSSFWorkbook may work. While writing out, you can make some modifications to the input data.

There are a couple of unit tests in excel-streaming-reader that do this. It is not an officially supported feature and anyone who want to try this out will need to do some experimentation and may lose some features from the input document due to potentially missing features in excel-streaming-reader or SXSSFWorkbook. Feel free to raise issues if you think some improvements can be made. I can collaborate with anyone who wants to add features but I reserve the right to not invest lots of my time adding features that may not be of general benefit.

The test util code is in CopyToSXSSFUtil.java.

Pointers:

  • This util requires excel-streaming-reader v4.0.0 and above.
  • You may need to enable/disable features in excel-streaming-reader using the Builder.
  • You may need to enable/disable features in CellCopyPolicy.
  • Hyperlink support is a little messy based on the fact the hyperlink data (as opposed to the display text for the cell) is stored at the end of the worksheet XML. The util has the logic to workaround this.
Clone this wiki locally