aspose file tools*
The moose likes Other Open Source Projects and the fly likes Java API for MS Excel 2010 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Java API for MS Excel 2010" Watch "Java API for MS Excel 2010" New topic
Author

Java API for MS Excel 2010

RajHans Kumar
Greenhorn

Joined: Apr 20, 2011
Posts: 19
Hi, could anyone tell me about a Java API which can extract data from an excel in MS-EXCEL 2010 format .
The poi apis (HSSF and XSSF) aren't working for me (.xlsx 2010 format).

Regards
RajHans
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

Not nearly enough drivel to qualify for Meaningless Drivel. The question looks meaningful, too. Let's move it to a less exalted forum...
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42279
    
  64
What does "aren't working for me" mean? Post the code you're using. POI in general is capable of working with XLSX files.


Ping & DNS - my free Android networking tools app
RajHans Kumar
Greenhorn

Joined: Apr 20, 2011
Posts: 19
The piece of code is given below --


It throws an error

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/dom4j/DocumentException
at org.apache.poi.openxml4j.opc.OPCPackage.init(OPCPackage.java:149)
at org.apache.poi.openxml4j.opc.OPCPackage.<init>(OPCPackage.java:136)
at org.apache.poi.openxml4j.opc.Package.<init>(Package.java:54)
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:81)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:220)
at org.apache.poi.util.PackageHelper.open(PackageHelper.java:39)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:186)

at the line of code XSSFWorkbook workbook = new XSSFWorkbook(fis);

I have tried putting the appropriate poi jars in the build path.Still,I am getting such exceptions.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42279
    
  64
The build path isn't used when running a program; you need to add all the jars to the classpath used at runtime.
RajHans Kumar
Greenhorn

Joined: Apr 20, 2011
Posts: 19
I have added all the jars in the classpath ,however still this exception

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/dom4j/DocumentException
at org.apache.poi.openxml4j.opc.OPCPackage.init(OPCPackage.java:149)
at org.apache.poi.openxml4j.opc.OPCPackage.<init>(OPCPackage.java:136)
at org.apache.poi.openxml4j.opc.Package.<init>(Package.java:54)
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:81)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:220)
at org.apache.poi.util.PackageHelper.open(PackageHelper.java:39)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:186)

For this line of code:-
XSSFWorkbook workbook = new XSSFWorkbook(fis);
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42279
    
  64
Apparently not.
RajHans Kumar
Greenhorn

Joined: Apr 20, 2011
Posts: 19
Hi
I have used the following jars
dom4j-full.jar
ooxml-schemas-1.0.jar
poi3.7-20101029.jar
poi-examples-3.7-20101029
poi-ooxml-schemas-3.7-20101029
poi-scratchpad-3.7-20101029
xmlbeans-2.3.0.jar

The CLASSPATH is as follows
D:\toold\poi-3.7-20101029;D:\toold\poi-ooxml-3.5-FINAL.jar;D:\toold\dom4j-full.jar;D:\toold\poi-3.7\dom4j-full.jar;D:\toold\poi-3.7\ooxml-schemas-1.0.jar;D:\toold\poi-3.7\poi3.7-20101029.jar;D:\toold\poi-3.7\poi-examples-3.7-20101029;D:\toold\poi-3.7\poi-ooxml-schemas-3.7-20101029;D:\toold\poi-3.7\poi-scratchpad-3.7-20101029;D:\toold\xmlbeans-2.3.0.jar
as given in the Environment Variable in the User Variables section.
RajHans Kumar
Greenhorn

Joined: Apr 20, 2011
Posts: 19
Is there anyother Jar needed ?
Is the classpath correct ?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42279
    
  64
D:\Sriraj\Santander\toold\poi-3.7-20101029

That's not a file.

D:\Sriraj\Santander\toold\poi-ooxml-3.5-FINAL.jar

You should use files that go together - don't mix 3.5 libs with 3.7 libs.

D:\Sriraj\Santander\toold\dom4j-full.jar
D:\Sriraj\Santander\toold\poi-3.7\dom4j-full.jar

Including the same file twice is a bad idea. That's also not the file shipped with POI; why are you using a different one?

D:\Sriraj\Santander\toold\poi-3.7\ooxml-schemas-1.0.jar

That looks outdated; it certainly isn't shipped with current POI versions. See the above comment about not mixing versioned libs.

D:\Sriraj\Santander\toold\poi-3.7\poi3.7-20101029.jar

That looks OK.

D:\Sriraj\Santander\toold\poi-3.7\poi-examples-3.7-20101029

That's not a file, either. (It's also examples that aren't generally used if you run your code.)

D:\Sriraj\Santander\toold\poi-3.7\poi-ooxml-schemas-3.7-20101029

Nor is this.

D:\Sriraj\Santander\toold\poi-3.7\poi-scratchpad-3.7-20101029

Or this.

D:\Sriraj\Santander\toold\xmlbeans-2.3.0.jar

I'm not sure if that's needed, but it probably can't hurt.
RajHans Kumar
Greenhorn

Joined: Apr 20, 2011
Posts: 19
Thanks a lot
That was silly
Now I have updated as per the comments and my classpath is
D:\toold\poi-jars\dom4j-1.6.1.jar;D:\toold\poi-jars\geronimo-stax-api_1.0_spec-1.0.jar;D:\toold\poi-jars\xmlbeans-2.3.0.jar;D:\toold\poi-jars\poi-ooxml-3.7-20101029.jar;D:\toold\poi-jars\poi-ooxml-schemas-3.7-20101029.jar;D:\toold\poi-jars\poi-scratchpad-3.7-20101029.jar;D:\toold\poi-jars\poi-3.7-20101029.jar;D:\toold\poi-jars\poi-examples-3.7-20101029.jar

I am still getting an exception
org.apache.poi.POIXMLException: org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]
at org.apache.poi.util.PackageHelper.open(PackageHelper.java:41)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:186)
RajHans Kumar
Greenhorn

Joined: Apr 20, 2011
Posts: 19
Any idea about this exception ?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Java API for MS Excel 2010