aspose file tools*
The moose likes Other Open Source Projects and the fly likes WorkbookFactory.create Throws java.lang.IllegalArgumentException 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 "WorkbookFactory.create Throws java.lang.IllegalArgumentException" Watch "WorkbookFactory.create Throws java.lang.IllegalArgumentException" New topic
Author

WorkbookFactory.create Throws java.lang.IllegalArgumentException

Pushpa Seekala
Greenhorn

Joined: Aug 07, 2012
Posts: 3
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

Joined: Nov 09, 2011
Posts: 1030
    
    5

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

Joined: Aug 07, 2012
Posts: 3
Thank you James, for you response. Just heard back from Upstream team. They use Excel 2007.
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

In your first post, you mention the file format .xls. The file format for Excel 2007 is .xlsx however (OOXML file format).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: WorkbookFactory.create Throws java.lang.IllegalArgumentException