• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Saurabh Pol
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Saurabh Pol
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic