Bug 57161 - Add a warning against opening Excel file with WorkbookFactory.create(File)
Summary: Add a warning against opening Excel file with WorkbookFactory.create(File)
Status: RESOLVED DUPLICATE of bug 58779
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.11-dev
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2014-10-29 08:59 UTC by Philippe Lhoste
Modified: 2016-04-05 16:20 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Philippe Lhoste 2014-10-29 08:59:54 UTC
I wrote code opening an Excel file (XLS or XLSX) with an InputStream. I modify the file, then I save it back. Worked well.
Re-reading the doc, I see that WorkbookFactory.create(File) uses less resources, so I used this method instead.
All my tests failed. I got, for XLSX, a message "Can't obtain the input stream from /docProps/app.xml", and for XLS, a message about an index out of bounds.

After investigation, I found I was not alone: http://stackoverflow.com/questions/14117617/apache-poi-unable-to-write-to-an-existing-workbook

So I just reverted to read my file from an input stream (it isn't big anyway).

I can understand it can be a limitation of the underlying system (Windows 7 here).
But I suggest you put a warning against this kind of usage, when you recommend to use this form of opening.
If you have a fix, or at least a way to make a friendlier error message, it would be even better...
Comment 1 Javen O'Neal 2016-04-05 16:20:56 UTC
This will be addressed in bug 58779, either as a documentation update or a change in behavior to workbook.close().

*** This bug has been marked as a duplicate of bug 58779 ***