• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

WorkbookFactory.create Throws java.lang.IllegalArgumentException

 
Pushpa Seekala
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

We receive an excel file from upstream which is .xls file but seems to be created with Excel 2007. When I open the file in a notebook it looks more like a html file. If I open the file on my machine and save as .xls file then below lines of code work perfectly fine otherwise throws java.lang.IllegalArgumentException: Your InputStream was neither an OLE2 stream, nor an OOXML stream.

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;

/*
some code
*/

fis = new FileInputStream(file);
Workbook workbook = WorkbookFactory.create(fis); //throws exception with latest version of excel.

Also, our code uses poi-3.6-20091214. Could someone please suggest how to make it work with both old and new excel.

Thanks,
Pushpa.
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The mission statement on the Apache POI site:

Apache POI is your Java Excel solution (for Excel 97-2008).


What version of Excel are you using? I suspect, judging by the statement above, that you are trying to use a version which is not supported.
 
Pushpa Seekala
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you James, for you response. Just heard back from Upstream team. They use Excel 2007.
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your first post, you mention the file format .xls. The file format for Excel 2007 is .xlsx however (OOXML file format).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic