This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes I have been trying to read an xlsx and have been getting errors while. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "I have been trying to read an xlsx and have been getting errors while." Watch "I have been trying to read an xlsx and have been getting errors while." New topic
Author

I have been trying to read an xlsx and have been getting errors while.

Kanwardeep Singh
Greenhorn

Joined: Dec 06, 2012
Posts: 10


public XSSFWorkbook createXSSFWorkbook( InputStream inputStream ) {

XSSFWorkbook workbook;
try {
workbook = new XSSFWorkbook(inputStream);

}
catch ( IOException ex ) {
trace.error( ex );
throw new RuntimeException( ex );
} catch (Exception e) {
trace.error( e );
throw new RuntimeException( e );
}

return workbook;
}
Kanwardeep Singh
Greenhorn

Joined: Dec 06, 2012
Posts: 10
Error comes on this line.
workbook = new XSSFWorkbook(inputStream);


Error stacktace is:
java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlOptions
at org.apache.poi.POIXMLDocumentPart.<clinit>(POIXMLDocumentPart.java:44)
at com.cassiopae.cassiopae.common.shared.util.ExcelImportHelper.createXSSFWorkbook(ExcelImportHelper.java:134)
at com.cassiopae.cassiopae.view.property.dlgUploadTenantsProperties.DlgUploadTenantsPropertiesUIBean.processDataFile(DlgUploadTenantsPropertiesUIBean.java:199)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.el.parser.AstValue.invoke(AstValue.java:151)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:283)
at org.apache.myfaces.trinidadinternal.taglib.util.MethodExpressionMethodBinding.invoke(MethodExpressionMethodBinding.java:53)
at org.apache.myfaces.trinidad.component.UIXComponentBase.broadcastToMethodBinding(UIXComponentBase.java:1213)
at org.apache.myfaces.trinidad.component.UIXEditableValue.broadcast(UIXEditableValue.java:214)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl$GrabEvents.broadcastEvents(LifecycleImpl.java:1109)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._executePhase(LifecycleImpl.java:320)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:177)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
at com.cassiopae.cassiopae.container.servlets.CassiopaeFacesServlet.service(CassiopaeFacesServlet.java:169)
at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)
at oracle.adfinternal.view.faces.webapp.rich.SharedLibraryFilter.doFilter(SharedLibraryFilter.java:135)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:281)
at oracle.adfinternal.view.faces.webapp.rich.RegistrationFilter.doFilter(RegistrationFilter.java:69)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:281)
at oracle.adfinternal.view.faces.activedata.ADSFilter.doFilter(ADSFilter.java:85)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:281)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._invokeDoFilter(TrinidadFilterImpl.java:241)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._doFilterImpl(TrinidadFilterImpl.java:198)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(TrinidadFilterImpl.java:141)
at org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFilter.java:92)
at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:15)
at oracle.adfinternal.view.faces.webapp.rich.SharedLibraryFilter.doFilter(SharedLibraryFilter.java:135)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:281)
at oracle.adfinternal.view.faces.webapp.rich.RegistrationFilter.doFilter(RegistrationFilter.java:69)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:281)
at oracle.adfinternal.view.faces.activedata.ADSFilter.doFilter(ADSFilter.java:85)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:281)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._invokeDoFilter(TrinidadFilterImpl.java:241)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._doFilterImpl(TrinidadFilterImpl.java:198)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(TrinidadFilterImpl.java:141)
at org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFilter.java:92)
at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:17)
at com.cj.trim.trimFilter.doFilter(Unknown Source)
at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:17)
at com.cj.gzipflt.GzipFilter.doFilter(Unknown Source)
at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:17)
at org.springframework.webflow.executor.jsf.FlowSystemCleanupFilter.doFilterInternal(FlowSystemCleanupFilter.java:41)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:17)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:17)
at oracle.security.jazn.oc4j.JAZNFilter$3.run(JAZNFilter.java:434)
at java.security.AccessController.doPrivileged(Native Method)
at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:308)
at oracle.security.jazn.oc4j.JAZNFilter.doFilter(JAZNFilter.java:452)
at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:583)
at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:334)
at com.evermind.server.http.HttpRequestHandler.doDispatchRequest(HttpRequestHandler.java:942)
at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:843)
at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:658)
at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:626)
at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:417)
at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:189)
at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:163)
at oracle.oc4j.network.ServerSocketReadHandler$ClientRunnable.run(ServerSocketReadHandler.java:275)
at oracle.oc4j.network.ServerSocketAcceptHandler.procClientSocket(ServerSocketAcceptHandler.java:237)
at oracle.oc4j.network.ServerSocketAcceptHandler.access$800(ServerSocketAcceptHandler.java:29)
at oracle.oc4j.network.ServerSocketAcceptHandler$AcceptHandlerHorse.run(ServerSocketAcceptHandler.java:877)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: oracle.classloader.util.AnnotatedClassNotFoundException:

Missing class: org.apache.xmlbeans.XmlOptions

Dependent class: org.apache.poi.POIXMLDocumentPart
Loader: current-workspace-app.web.Cassiopae:0.0.0
Code-Source: /D:/WorkSpaces/CBRE/Cassiopae/lib/POI/poi-ooxml-3.7.jar
Configuration: <classpath> in D:\WorkSpaces\CBRE\Cassiopae\public_html

This load was initiated at current-workspace-app.web.Cassiopae:0.0.0 using the loadClass() method.

The missing class is not available from any code-source or loader in the system.
at oracle.classloader.PolicyClassLoader.handleClassNotFound(PolicyClassLoader.java:2169)
at oracle.classloader.PolicyClassLoader.internalLoadClass(PolicyClassLoader.java:1716)
at oracle.classloader.PolicyClassLoader.loadClass(PolicyClassLoader.java:1672)
at oracle.classloader.PolicyClassLoader.loadClass(PolicyClassLoader.java:1657)
... 70 more
Process exited.


Actually I need to read and xlsx file ..so can you directly give me the code for reading the code from the .xlsx file and also let me know the jars associated as well.
i cant give you the different errors,as i have tried adding the jars,the jars have dependency on other jars.so that chain continues.

please give the code,that can help fastly.


CAN WE USE SXSSFWorkBook to read?
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3429
    
  12
Do you think it might be helpful to actually tell us what the error is ?


Joanne
Vinod Tiwari
Ranch Hand

Joined: Feb 06, 2008
Posts: 459
    
    1
Missing class: org.apache.xmlbeans.XmlOptions

Check if your jar is in classpath


Vinod Tiwari | Twitter
Kanwardeep Singh
Greenhorn

Joined: Dec 06, 2012
Posts: 10
Can some one give me the code to read the .xlsx file in java and please do tell the jars required for that...i have been trying but i have not found success till now.
please post this ASAP.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41123
    
  45
All the jar files you need come with Apache POI. Which steps have you taken to follow up on Vinod's suggestion?


Ping & DNS - my free Android networking tools app
Edson Cezar
Ranch Hand

Joined: Mar 05, 2011
Posts: 75
    
    1
I think you need this code

Apache POI


I hope help you
Kanwardeep Singh
Greenhorn

Joined: Dec 06, 2012
Posts: 10
i have tried this,but did not work.
presently i am working this problem out by this code.

package cassiopae;

import org.apache.poi.xssf.usermodel.XSSFRow;


import java.io.*;

import java.util.*;

import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class Test
{

public static void main( String[] args ) {

String fileName = "D:\\FIC_UPDATE_LAGUNAV2.xlsx";
Vector dataHolder = ReadFile( fileName );
read( dataHolder );
}

public static Vector ReadFile( String fileName ) {
Vector cellVectorHolder = new Vector();
try {
FileInputStream arquivo = new FileInputStream( fileName );
XSSFWorkbook planilha = new XSSFWorkbook(OPCPackage.open(arquivo));
XSSFSheet aba = planilha.getSheetAt( 0 );
Iterator rowIter = aba.rowIterator();

while ( rowIter.hasNext() ) {
XSSFRow myRow = ( XSSFRow )rowIter.next();
Iterator cellIter = myRow.cellIterator();

Vector cellStoreVector = new Vector();
while ( cellIter.hasNext() ) {

XSSFCell myCell = ( XSSFCell )cellIter.next();
cellStoreVector.addElement( myCell );
}
cellVectorHolder.addElement( cellStoreVector );
}
}
catch ( Exception e ) {
System.out.println("--------------error occured--------------" );
System.out.println( e.getMessage());

}
return cellVectorHolder;
}

private static void read( Vector dataHolder ) {
for ( int i = 0; i < dataHolder.size(); i++ ) {
Vector cellStoreVector = ( Vector )dataHolder.elementAt( i );

for ( int j = 0; j < cellStoreVector.size(); j++ ) {
XSSFCell myCell = ( XSSFCell )cellStoreVector.elementAt( j );
String stringCellValue = myCell.toString();
System.out.print( stringCellValue + "\t" );
}
System.out.println();
}

}
}

But the InvocationTargetException is coming on the bold line.
XSSFWorkbook planilha = new XSSFWorkbook(OPCPackage.open(arquivo));

can anyone tell why is so?
i have given all the jars in the path.
please suggest a solution.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4167
    
  21

Read the API for InvocationTargetException (<= that's a link to the API). It tells you when it would be thrown. It also tells you that, unfortunately you can't tell what the cause of the problem is from simply saying it is an InvocationTargetException. You need the exception which caused the InvocationTargetException. The API tells you how to get that.


Steve
Kanwardeep Singh
Greenhorn

Joined: Dec 06, 2012
Posts: 10
dom4j-1.6.1.jar
log4j-1.2.16.jar
ooxml-schemas-1.1.jar
poi-3.7-20101029.jar
poi-ooxml-3.7.jar
poi-ooxml-schemas-3.7.jar
stax-api-1.0.1.jar
xmlbeans-2.4.0.jar

PUTTING THESE JARS FILE WILL SOLVE THE PROBLEM.
thanks to the solution...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I have been trying to read an xlsx and have been getting errors while.
 
Similar Threads
POI: Writing Workbook twice doesn't work
file Writing problem
sheet.getLastRowNum() returns -1
OutOfMemoryError in processing large xlsx file (167 MB) using Apache POI
Read a .xls,.xlsx file format using XSSF