您好我正在尝试在Liferay的网络服务电话中阅读excel(.xlsx)文件。
这是我的代码
public JSONArray getProductListing() throws IOException,
FileNotFoundException {
try {
JSONArray jArray = com.liferay.portal.kernel.json.JSONFactoryUtil
.createJSONArray();
FileInputStream file = new FileInputStream(
new File(
"/home/onrule/GITLAB/OnRule-3.0-Core/XLS2SQL_Folder/XLS/product-portlet/PRODUCTS_DATA.xlsx"));
// Create Workbook instance holding reference to .xlsx file
Workbook workbook = new XSSFWorkbook(file);
// Get first/desired sheet from the workbook
Sheet sheet = workbook.getSheetAt(0);
// Iterate through each rows one by one
Iterator rowIterator = sheet.iterator();
while (rowIterator.hasNext()) {
Row row = (Row) rowIterator.next();
// For each row, iterate through all the columns
Iterator<Cell> cellIterator = row.cellIterator();
// Create JSONArray for each row.
JSONArray lineArray = com.liferay.portal.kernel.json.JSONFactoryUtil
.createJSONArray();
while (cellIterator.hasNext()) {
Cell cell = cellIterator.next();
lineArray.put(cell.getStringCellValue());
}
jArray.put(lineArray);
}
System.out.println("bye");
return jArray;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
我正在
java.lang.ExceptionInInitializerError
at org.apache.poi.openxml4j.opc.internal.unmarshallers.PackagePropertiesUnmarshaller.<clinit>(PackagePropertiesUnmarshaller.java:49)
at org.apache.poi.openxml4j.opc.OPCPackage.init(OPCPackage.java:154)
at org.apache.poi.openxml4j.opc.OPCPackage.<init>(OPCPackage.java:141)
at org.apache.poi.openxml4j.opc.Package.<init>(Package.java:54)
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:82)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:267)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:73)
at com.onrule.core.standard.service.impl.GrpServiceImpl.getProductListing(GrpServiceImpl.java:80)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:115)
at com.liferay.portal.spring.transaction.DefaultTransactionExecutor.execute(DefaultTransactionExecutor.java:62)
at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:51)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:111)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
at org.dom4j.DocumentFactory.getInstance(DocumentFactory.java:97)
at org.dom4j.tree.AbstractNode.<clinit>(AbstractNode.java:39)
... 107 more
我第一次尝试调用Web服务时。 但在第一次错误改变之后 无法初始化类
org.apache.poi.openxml4j.opc.internal.unmarshallers.PackagePropertiesUnmarshaller
我已经在java构建路径中使用了openxml4j jar。其中包含 org.apache.poi.openxml4j.opc.internal.unmarshallers.PackagePropertiesUnmarshaller 类。
我调试了我的代码,直到Workbook workbook = new XSSFWorkbook(file);
行才能正常工作。
有人有任何解决方案吗?