I've always been able to use POI via JavaLoader to read in standard xls
files and extract data out of the cells for whatever I want, like
storing in a database. Recently, I've had to start coding to handle
Office 2007 file formats like xlsx and xlsm. POI 3.5 and higher should
be able to do that according to many examples I've found on the internet
and in Apache's own documentation. So, I'm currently using ColdFusion 9,
JavaLoader 1.0, and POI 3.8b4. For the record, I've also tried POI 3.6
and 3.7 for this test and sample code below. Here is my sample code:
<cfoutput>
<cfset var.JLKey = "93345778-4949-4705-1235577891134557" />
<cfset var.paths = []>
<cfset var.jarpath = "/Users/mstaver/workspace/Fimble/ExternalCode" />
<!--- location of POI jars --->
<cfdirectory action="list" name="files" directory="#var.jarpath#"
filter="*.jar" recurse="true" />
<cfloop query="files">
<cfset arrayAppend(var.paths, directory & "/" & name) />
</cfloop>
<cfif NOT structKeyExists(server, var.JLKey)>
<cfset server[var.JLKey] = createObject("component",
"component.JavaLoader").init(loadPaths=var.paths,
loadColdFusionClassPath=false) />
</cfif>
<cfscript>
fileAndPath = "/Users/mstaver/workspace/Fimble/11g.xlsm";
inp = createObject("java", "java.io.FileInputStream").init("#fileAndPath#");
objWorkBook =
server[var.JLKey].create("org.apache.poi.xssf.usermodel.XSSFWorkbook").Init(inp);
</cfscript>
</cfoutput>
When I write use this code with one small tweak (HSSF instead of XSSF)
and I feed in an xls file, everything works as expected. However, when I
use the exact code above and feed it xlsx or xlsm, I get this error:
Object instantiation exception.
An exception occurred while instantiating a Java object. The class must
not be an interface or an abstract class. Error: ''. The error occurred
in */Users/mstaver/workspace/Fimble/test.cfm: line 18*
*Called from* /Users/mstaver/workspace/Fimble/Application.cfc: line 97
*Called from* /Users/mstaver/workspace/Fimble/test.cfm: line 18
*Called from* /Users/mstaver/workspace/Fimble/Application.cfc: line 97
16 : fileAndPath = "/Users/mstaver/workspace/Fimble/11g.xlsm";
17 : inp = createObject("java",
"java.io.FileInputStream").init("#fileAndPath#");
*18 : objWorkBook =
server[var.JLKey].create("org.apache.poi.xssf.usermodel.XSSFWorkbook").Init(inp);*
Further down the error stack, I think this is relevant:
Caused by: java.lang.NoClassDefFoundError: Could not initialize class
org.apache.poi.openxml4j.opc.internal.unmarshallers.PackagePropertiesUnmarshaller
I don't know where to go on this one. I've tried the SS method, instead
of XSSF - and it works fine, until I feed it an xlsx or xlsm again. I
don't get it. I've also tried this on Windows 2003, besides here on my
Macbook. Both machines are running CF 9.0.1. I'm getting the impression
that I'm missing a class or something. I've followed examples from all
over the web, and from the POI docs. Everything works until I feed it
Office 2007 format docs...
-------------------------------------------------------------
To unsubscribe from this list, manage your profile @
http://www.acfug.org?fa=login.edituserform
For more info, see http://www.acfug.org/mailinglists
Archive @ http://www.mail-archive.com/discussion%40acfug.org/
List hosted by http://www.fusionlink.com
-------------------------------------------------------------