Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

apache poi excel workbook won't open after download

 
Tommi Vd
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am trying to export a report to an excel file and then download it.

the code:



It download ok, the size of the file is ok and when i try to open it in openoffice it works.
But when i try to open it in microsoft office excel it crashes, saying there is a problem and excel will be shut down...

Anyone please i have absolutely no idea
Also is the deprecated, anyone an alternative?
I also can't seem to create an , only a ...

kind regards,

Thomas
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What versions of POI, Excel and OO are you using? I don't know this library at all but it might be worth testing against different versions of Excel and see if it's a common problem across all versions
 
Tommi Vd
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
excel 2007, i do not have a lower version... :s
and poi-3.2-FINAL jar

i can't find what's wrong, anybody?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The easiest way to replace the deprecated setCellValue("string") is by using setCellValue(new HSSFRichTextString("string")), just like the javadocs suggest.

What exactly do you mean by "I also can't seem to create an XSSFWorkbook"? How are you trying to do so? I think it depends on the filename - try with a ".xlsx" extension instead of ".xls".

This page may be of interest if you've used POI 3.2 (or older) before: http://poi.apache.org/spreadsheet/converting.html
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and poi-3.2-FINAL jar

POI 3.2 does not support the Office XML formats; you need to use the POI 3.5 beta for that (which, despite being a beta, is quite stable, and an improvement even if you use it for the old binary formats).
 
Tommi Vd
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi thanks for the reply,

I changed xls to xlsx and added the 3.5 beta instead of the poi-3.1.

But the problem is still there, however i get an error message now if i want to open the downloaded excel file:

Excel cannot open the file 'IndividualReport-WimTobback.xslx' because the file format or the file extension is not valid.
Verify that the file has not been corrupted and that the file extension matches the format of the file.



Idea?

kind regards,

Thomas
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does it work if -instead of streaming it- you save it to a file, and then open that file directly?

Is the streamed file's size the same as the byte array size before streaming?
 
Tommi Vd
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok the size is the same, just al little difference (100 bytes something)

When i use a fileoutputstream i can open the files with xls extension without a problem, xlsx gives the same problem.
So i thought maybe when is tream now with an .xls extension it work, but no i got the same as before but i do not get the error message, it now just says
that it stopped working...

man i'm going crazy...

regards,

Thomas
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For a binary file, a missing (or extra) 100 bytes can be a killer. You need to find out where those are coming from.
 
Tommi Vd
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any tips how you can do that?
 
Tommi Vd
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The size seems to be the same now ...

I'm so stuck on this :s
 
Tommi Vd
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nobody? I'm still looking but...
 
Javier Reyes
Greenhorn
Posts: 1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
instead of OutputStream i used ByteArrayOuputStream just like this



the detail in here is that the HSSFWorkbook object must be the one writing on a OutputStream, not in the other way, i had a similar problem but this solved it, now i can open excel files generated by my aplication without problem

by the way im using poi-3.2-FINAL-20081019

cheers
 
rober alonso
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Javier Reyes wrote:instead of OutputStream i used ByteArrayOuputStream just like this



the detail in here is that the HSSFWorkbook object must be the one writing on a OutputStream, not in the other way, i had a similar problem but this solved it, now i can open excel files generated by my aplication without problem

by the way im using poi-3.2-FINAL-20081019

cheers


thanks Javier, this solve my problem. Now im using 'byteRpt' instead of workbook.getBytes() and its works.

gracias amigo
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic