This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Other Open Source Projects and the fly likes Apache POI, FormFile, and XSSF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Apache POI, FormFile, and XSSF" Watch "Apache POI, FormFile, and XSSF" New topic
Author

Apache POI, FormFile, and XSSF

Pat Flickner
Ranch Hand

Joined: Nov 17, 2003
Posts: 173
I'm having some major difficulty here that I'm hoping someone can help me with. I've googled my brains out trying to find an answer that works, and am having no success. We are now standardized at Excel 2007 and our users want to not have to save the files as 97-2003 format just to read the file. The problem I'm having is that I'm using the apache struts FormFile. XSSF does not care for the InputStream with FormFile. I've tried creating a new FileInputStream using the full path (I extract that prior to uploading so that it's part of the ActionForm) and using the full path (which includes the filename) for creating the new Workbook. I've tried a variety of things, including using the WorkbookFactory. I'm at a loss. Everthing I see says it tells you how to read a 2007 Excel file, but all of their examples are for ".xls" files. I have no doubt they work, but I would like to see something for 2007+ format.

Here's the code:



Maybe I missed something, but I'm now pounding my head against a brick wall. This is my umpteenth iteration at trying something to make this work. I appreciate any information that may help. I'm willing to try anything, including standing on my head reciting Shakespeare. If that works, I'll take it.

Pat Flickner
Pat Flickner
Ranch Hand

Joined: Nov 17, 2003
Posts: 173
By the way, I'm using eclipse Helios release 2 with the WebSphere jdk. I get the following error:

Pat Flickner
Ranch Hand

Joined: Nov 17, 2003
Posts: 173
I added the dom4j.jar to my classpath (found that somewhere, figured I'd try it) and now I'm getting "org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException". Am I missing a jar or something? Here's what I have besides my spring and struts jars:

<classpathentry kind="lib" path="Web Content/WEB-INF/lib/commons-beanutils-1.8.0.jar"/>
<classpathentry kind="lib" path="Web Content/WEB-INF/lib/commons-collections-3.2.1.jar"/>
<classpathentry kind="lib" path="Web Content/WEB-INF/lib/commons-dbcp-1.2.2.jar"/>
<classpathentry kind="lib" path="Web Content/WEB-INF/lib/commons-digester-2.1.jar"/>
<classpathentry kind="lib" path="Web Content/WEB-INF/lib/commons-fileupload-1.2.1.jar"/>
<classpathentry kind="lib" path="Web Content/WEB-INF/lib/commons-io-1.4.jar"/>
<classpathentry kind="lib" path="Web Content/WEB-INF/lib/commons-jexl-2.0.1.jar"/>
<classpathentry kind="lib" path="Web Content/WEB-INF/lib/commons-lang-2.4.jar"/>
<classpathentry kind="lib" path="Web Content/WEB-INF/lib/commons-logging-1.1.1.jar"/>
<classpathentry kind="lib" path="Web Content/WEB-INF/lib/commons-logging-adapters-1.1.1.jar"/>
<classpathentry kind="lib" path="Web Content/WEB-INF/lib/commons-logging-api-1.1.1.jar"/>
<classpathentry kind="lib" path="Web Content/WEB-INF/lib/commons-pool-1.4.jar"/>
<classpathentry kind="lib" path="Web Content/WEB-INF/lib/commons-validator-1.3.1.jar"/>
<classpathentry kind="lib" path="Web Content/WEB-INF/lib/dom4j-full.jar"/>
<classpathentry kind="lib" path="Web Content/WEB-INF/lib/junit-3.8.1.jar"/>
<classpathentry kind="lib" path="Web Content/WEB-INF/lib/jxls-core-1.0-RC-2.jar"/>
<classpathentry kind="lib" path="Web Content/WEB-INF/lib/jxls-reader-1.0-RC-2.jar"/>
<classpathentry kind="lib" path="Web Content/WEB-INF/lib/log4j-1.2.16.jar"/>
<classpathentry kind="lib" path="Web Content/WEB-INF/lib/ooxml-schemas-1.1.jar"/>
<classpathentry kind="lib" path="Web Content/WEB-INF/lib/poi-3.7-20101029.jar"/>
<classpathentry kind="lib" path="Web Content/WEB-INF/lib/poi-ooxml-3.7-20101029.jar"/>
<classpathentry kind="lib" path="Web Content/WEB-INF/lib/poi-ooxml-schemas-3.7-20101029.jar"/>
<classpathentry kind="lib" path="Web Content/WEB-INF/lib/poi-scratchpad-3.7-20101029.jar"/>
<classpathentry kind="lib" path="Web Content/WEB-INF/lib/xbean.jar"/>

I figue if I'm now getting another message, I must be missing something, or something I have is too old (or new) for the processes.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Yes, I expect you are missing one of the required jars. I know I had to go through that cycle a couple of times. The stack trace you got (but didn't post) should contain useful information about what that exception was all about.
Pat Flickner
Ranch Hand

Joined: Nov 17, 2003
Posts: 173
I wish. I looked at the list of jar files I'm supposed to have on the Apache site and even added a few (like the dom4j.jar file - that isn't on the list). I'm getting a org.apache.poi.POIXMLException error: org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException. The stack trace is null. There is no other information and it's driving me crazy. The only thing I don't have is thte xmlbean jar. I think that's right. I will try adding that and see if that works. It's the only thing I haven't tried (just came across that).
Pat Flickner
Ranch Hand

Joined: Nov 17, 2003
Posts: 173


SON OF A GUN!!! That did it. Here's my final portion (I actually had the xbean.jar (and possibly an older version that the one I downloaded and replaced it with), but I was missing the other things that were in the lib:

<classpathentry kind="lib" path="Web Content/WEB-INF/lib/jsr173_1.0_api.jar"/>
<classpathentry kind="lib" path="Web Content/WEB-INF/lib/resolver.jar"/>
<classpathentry kind="lib" path="Web Content/WEB-INF/lib/xbean_xpath.jar"/>
<classpathentry kind="lib" path="Web Content/WEB-INF/lib/xmlbeans-qname.jar"/>
<classpathentry kind="lib" path="Web Content/WEB-INF/lib/xmlpublic.jar"/>


That did it! I added the other ones and I can now read xlsx files. Now I can play. YAY!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Apache POI, FormFile, and XSSF