1

I am using the following lines to open an empty Excel 2007 document:

OPCPackage opcPackage = OPCPackage.openOrCreate(file)
wb = new XSSFWorkbook(opcPackage);

The funny thing is, it is taking 20 seconds just to do that. Why?

Others were complaining about XSSF because it is taking too slow to load a huge file. But for me it is just an empty file that should be done in not even 1 second!

Yannick Wald
  • 185
  • 1
  • 4
  • 13
  • POI has some problems when dealing with XSSF format. It is slow and will eat up an awful lot of memory to open even a 10 MB `.xlsx` file. --- [I have a 141 MB file I'm still unable to open](http://stackoverflow.com/questions/11891851/how-to-load-a-large-xlsx-file-with-apache-poi). --- I suggest evading POI as much as possible when it comes to `.xlsx`files. – CosmicGiant Nov 09 '12 at 16:33
  • 1
    Is the file on a slow remote drive by any chance? And are you sure it's really empty? Loading an almost empty .xlsx file in POI should take well under a second... – Gagravarr Nov 10 '12 at 21:46
  • i deleted every single cell but still the same.. at least i know it now that it should load under a second.. probably the file is corrupt? – Yannick Wald Nov 12 '12 at 15:55

1 Answers1

0

Just a guess: I am not sure if the file you're producing is a valid xlsx file. Maybe it takes so long because it is not created as excel workbook.

As for the library efficiency: there is a question somewhere here about fast xlsx writing and poi performs excellently using SXSSF library branch. Not sure if it supports reading though.

Jarekczek
  • 7,456
  • 3
  • 46
  • 66
  • it has been created as an excel 2007 workbook and saved it as .xlsx. but probably it turned corrupt after a while.. i don't know. – Yannick Wald Nov 12 '12 at 15:56
  • If this is the case, then you could produce a new file using [User api example](http://poi.apache.org/spreadsheet/how-to.html#user_api) from POI webpage. Just replace the `HSSF` constructor with `XSSF` and change the name to `.xlsx`. And make sure you work with latest poi version, 3.8. – Jarekczek Nov 12 '12 at 16:02
  • i was working with xssf since the beginning. also, i deleted it and created a new one from the code ive written. perhaps i should try to delete the file and create a new one, but from excel itself. if this works under a second there is an issue with my code. for the next three days i don't have access to it. i will let you know as soon ill have tried it out. – Yannick Wald Nov 12 '12 at 16:08
  • i created a new project just to load an empty xlsx-file generated in excel and it still took 20 seconds. then i changed to poi3.9(beta) and it took only 10 seconds. – Yannick Wald Nov 15 '12 at 10:12
  • doing the same with .xls using new HSSFWorkbook(..): 280 ms – Yannick Wald Nov 15 '12 at 10:13
  • Interesting finding. Sounds like something to report as a bug. – Jarekczek Nov 15 '12 at 14:36