Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

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

 
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.
 
Rancher
Posts: 43011
76
  • 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: 43011
76
  • 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.
 
Did you just should on me? You should read this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!