MRalwasser
MRalwasser

Reputation: 15973

Apache POI: Is it possible to use SXSSF without temporary files?

I'd like to use SXSSF (Streaming Usermodel API) from Apache POI.
What I don't like is that it uses temporary files.

Question:

Is it possible in Apache POI to flush directly to the output stream without the use of temporary files?

Upvotes: 5

Views: 5018

Answers (4)

PJ Fanning
PJ Fanning

Reputation: 1046

POI 5.2.+ has DeferredSXSSFWorkbook which uses fewer temp files. See https://svn.apache.org/repos/asf/poi/trunk/poi-examples/src/main/java/org/apache/poi/examples/xssf/streaming/DeferredGeneration.java

Upvotes: 1

Somanath Behera
Somanath Behera

Reputation: 11

Yes we can stop the temp file generation during excel file generation. Either you have to zip the temp file or dispose the temp file. But dispose is recommended as the file will not be created again if you call the dispose method.

Code Snippet

SXSSFWorkbook wb = new 
SXSSFWorkbook(100);

// write your code.

wb.dispose();  
// This method will help to stop the temp file generation.

Upvotes: 1

Somanath Behera
Somanath Behera

Reputation: 11

You can also compress the file

wb.setCompressTempFiles(true);

It will make a zip file of the temp file. But dispose is recommended.

Upvotes: 0

Gagravarr
Gagravarr

Reputation: 48376

No

In order to generate a valid Excel .xlsx file, there are various bits of the file which need to agree with each other. These references, links, ids etc need to be updated by Apache POI when writing the file out

You therefore have two options:

  • XSSF - No temporary files, everything very easy to work with, everything kept in memory
  • SXSSF - Various restrictions, large parts streamed into temporary files, small bits in memory

If you don't want temp files, buy some more memory and use XSSF!

Also, don't forget that you can control where POI places the temporary files, if the default doesn't work well for you

Upvotes: 4

Related Questions