wood burning stoves 2.0*
The moose likes Other Open Source Projects and the fly likes JSF: HSSFWorkbook - handling csv, xls and xlsx file. 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 "JSF: HSSFWorkbook - handling csv, xls and xlsx file." Watch "JSF: HSSFWorkbook - handling csv, xls and xlsx file." New topic
Author

JSF: HSSFWorkbook - handling csv, xls and xlsx file.

Saurabh Pol
Greenhorn

Joined: Dec 05, 2012
Posts: 12
Hi All,

I am getting exception while uploading the xlsx and csv file.

I have to use same upload functionality for all csv, xls and xlsx.

but HSSFWorkbook is throwing exceptions as bellow.

for csv: java.io.IOException: Unable to read entire header; 27 bytes read; expected 32 bytes

for xlsx: The supplied data appears to be in the Office 2007+ XML..
You are calling the part of POI that deals with OLE2 Office Documents.
You need to call a different part of POI to process this data (eg XSSF instead of HSSF)

for xls file its working fine.


can you please help me to handle these three types of file using HSSFWorkbook.

Thanks and Regards,
Saurabh Pol.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41863
    
  63
This has nothing to do with either the act of uploading files, nor with JSF. The reason is that apparently the code tries to open the file after uploading, and the library classes you're using (HSSF) simply can't handle XLSX files. The solution is to rewrite your code to handle both XLS and XLSX files by using the SS classes. This should help: http://poi.apache.org/spreadsheet/converting.html


Ping & DNS - my free Android networking tools app
Saurabh Pol
Greenhorn

Joined: Dec 05, 2012
Posts: 12
Thank you Ulf,

Now I am able to manage xls and xlsx but I am not getting what to do for csv files.
could you please help me to get some idea.

Thanks and Regards,
Saurabh Pol

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41863
    
  63
What has the code previously been doing with CSV? I don't know what kind of support POI has for CSV; probably not much. But there are any number of libraries out there that can read CSVs. Given that it's a relatively simple format, those aren't hard to use.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSF: HSSFWorkbook - handling csv, xls and xlsx file.