Hi All,
I'm running into some errors when trying to import an xls file:
"java.lang.Exception: Invoke failed: [[c:WorkbookFactory]]->create((o:InputStream)[o:FileInputStream]). Cause: java.lang.NoSuchMethodError: org.apache.poi.poifs.filesystem.POIFSFileSystem.hasPOIFSHeader(Ljava/io/InputStream;)Z VM: 1.6.0_16@http://java.sun.com/" at: #-10 org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:59)
I'm thinking that this may be related to the Java autoloader issue, so I tried this:
// $workbook = org_apache_poi_ss_usermodel_WorkbookFactory::type()->create($inp);
$WbClass = new java_class('org.apache.poi.ss.usermodel.WorkbookFactory');
$workbook = $WbClass->create($inp);
Didn't seem to make a difference... however I did not change how $inp was getting initialized (I don't see an error associated with it). Not sure how to pass in a param w/ single quotes using that syntax.
Also, it may be worth noting that I cannot get the php and jsp samples for PhpJavaBridge to work at the same time. I have an Apache-Tomcat connector, and when I enable this for JavaBridge, the jsp examples work, but the php examples do not. If I have it disabled, the php examples work, but jsp examples don't. Is that normal? Will the JavaBridge still function/function well enough for sheetnode to work? (Sorry if that's more of a PhpJavaBridge question)
Any help would be appreciated. Thanks!
Comments
Comment #1
nsoules1 commentedComment #2
infojunkieI tested XLS import with the latest Apache POI 3.6 distribution: it seemed to run fine on my side. Please make sure that you don't have an older version of POI somewhere where it gets picked up by the Java runtime.
Concerning the PHP vs JSP samples: I've never used the Apache-Tomcat connector so I can't help troubleshoot this area. However, are you able to run this Excel example ?
Comment #3
nsoules1 commentedKratib - that example worked with the Apache-Tomcat connecter off, but not with it on, like all the PHP examples in JavaBridge. JSP examples don't work when it's offf. I'll leave it off for the sake of any testing here.
Comment #4
infojunkieCan you find out the versions of the following components:
- PHP/Java Bridge
- Tomcat (if you use it to run PHP/Java Bridge)
- Server OS
- Apache POI
If you can write Java code, please try the following snippet (in the same environment as PHP/Java Bridge):
(Taken from the Apache POI docs). Do you get the same error with
WorkbookFactory.create()?Comment #5
nsoules1 commentedHey Kratib,
Versions:
- PHP/Java Bridge
5.5.1
- Tomcat (if you use it to run PHP/Java Bridge)
5.5.27
- Server OS
Linux 2.6.9-67
- Apache POI
3.5-FINAL
I'll see about doing the java test.
Comment #6
nsoules1 commentedKratib,
I've tried the example you've given me, but I'm running into some issues w/ the import/includes:
package org.apache.poi.hssf.model does not exist
[javac] import org.apache.poi.hssf.model.Workbook;
I've tried with "import org.apache.poi.*;" as well, to no avail.
I've tried adding adding the .jar file to jre/lib/ext, and adding the .jar file to my build.xml file for ANT, and neither worked.
I can clearly see the Workbook class in the .jar file:
org/apache/poi/hssf/model/Workbook.class
When doing jar tvf.
I also tried the example in Apache POI FAQs, to check for previous versions of POI: http://poi.apache.org/faq.html#faq-N10006, but I got a similar error message:
package org.apache.poi.poifs.filesystem does not exist
[javac] ClassLoader classloader = org.apache.poi.poifs.filesystem.POIFSFileSystem.class.getClassLoader();
So it seems that I need to add the poi jar file *somewhere* for the Java Compiler to recognize it. I'm not entirely familiar with Java, so I could be missing something entirely obvious.
Again, any help appreciated. Thanks.
Comment #7
nsoules1 commentedBTW, tried editing CLASSPATH to have poi jar file, and now getting:
cannot find symbol
[javac] symbol : class Workbook
[javac] Workbook wb = WorkbookFactory.create(inp);
[javac] ^
Comment #8
nsoules1 commentedUpdate:
I've made some changes to classpath, and found out that I had a few missing .jar files for Apache POI in etc/lib. Now I'm able to run the POI Version check: http://poi.apache.org/faq.html#faq-N10006. I've tried to run this simple example (
http://poi.apache.org/spreadsheet/quick-guide.html#NewWorkbook):
Workbook wb = new HSSFWorkbook();
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
But I get this error:
[javac] /opt/bcs/packages/jakarta-tomcat5-5.5.27/webapps/JavaBridge/WbExample/src/WbExample.java:47: incompatible types
[javac] found : org.apache.poi.hssf.usermodel.HSSFWorkbook
[javac] required: org.apache.poi.hssf.model.Workbook
[javac] Workbook wb = new HSSFWorkbook();
If I instead use HSSFWorkbook wb = HSSFWorkbook(); it works fine, and I'm able to see the new .xls file outputted. I don't understand why it doesn't seem to think a generic Workbook can be initialized as a HSSFWorkbook. I get a similar error trying to run the example that you recommended earlier:
[javac] /opt/bcs/packages/jakarta-tomcat5-5.5.27/webapps/JavaBridge/WbExample/src/WbExample.java:62: incompatible types
[javac] found : org.apache.poi.ss.usermodel.Workbook
[javac] required: org.apache.poi.hssf.model.Workbook
[javac] Workbook wb = WorkbookFactory.create(inp);
Note that my changes have not fixed my original error w/ the sheetnode module.
As always, any help appreciated.
Comment #9
infojunkieThe latest 1.5-beta3 version has removed the Java dependencies and replaced them with PHPExcel library. Please delete your sheetnode folder and install the latest version as per the instructions on the module page.