aspose file tools*
The moose likes Other Open Source Projects and the fly likes apache poi excel workbook won't open after download Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "apache poi excel workbook won Watch "apache poi excel workbook won New topic
Author

apache poi excel workbook won't open after download

Tommi Vd
Ranch Hand

Joined: Apr 23, 2009
Posts: 49
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

Joined: Jun 24, 2003
Posts: 3274
    
    5

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


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Tommi Vd
Ranch Hand

Joined: Apr 23, 2009
Posts: 49
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
Marshal

Joined: Mar 22, 2005
Posts: 42950
    
  72
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
Marshal

Joined: Mar 22, 2005
Posts: 42950
    
  72
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

Joined: Apr 23, 2009
Posts: 49
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
Marshal

Joined: Mar 22, 2005
Posts: 42950
    
  72
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

Joined: Apr 23, 2009
Posts: 49
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
Marshal

Joined: Mar 22, 2005
Posts: 42950
    
  72
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

Joined: Apr 23, 2009
Posts: 49
any tips how you can do that?
Tommi Vd
Ranch Hand

Joined: Apr 23, 2009
Posts: 49
The size seems to be the same now ...

I'm so stuck on this :s
Tommi Vd
Ranch Hand

Joined: Apr 23, 2009
Posts: 49
Nobody? I'm still looking but...
Javier Reyes
Greenhorn

Joined: Aug 01, 2012
Posts: 1
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: apache poi excel workbook won't open after download