Opening XLSX or XLSM files via Aspose.Cells for Java in ColdFusion

I have a need to open up an XLSM file and add data to an existing sheet. The data I'd be added would be columns worth of information. As my first step to see if I could use Aspose.Cells(I downloaded the latest version and am using the jar file for JDK 1.6) for this I have been trying just to open up the file. My attempts to open up an XLSM(I tried and XLSX as well but got the same error) have been unsuccessful. The problem stems from when I try to pass the file name to the "Workbook". Here is my test code:


objFileFormatType = CreateObject("java", "com.aspose.cells.FileFormatType");

objLoadOptions = CreateObject("java", "com.aspose.cells.LoadOptions").init(objFileFormatType.XLSM);

objWorkBook = CreateObject("java", "com.aspose.cells.Workbook").init("C:\InductionHistoricalComparisonSpreadsheet.xlsm", objLoadOptions);

Here is the error that happens when I try executing it:

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 D:\inetpub\wwwroot\Projects\RRS\DeleteMe.cfm: line 58
56 : objLoadOptions		= CreateObject("java", "com.aspose.cells.LoadOptions").init(objFileFormatType.XLSM);
57 : 
58 : objWorkBook			= CreateObject("java", "com.aspose.cells.Workbook").init("C:\InductionHistoricalComparisonSpreadsheet.xlsm", objLoadOptions);
59 : 

Hi,

Thanks for your posting and using Aspose.Cells for Java.

Please download and try the latest version:
Aspose.Cells
for Java v7.2.2.1



Could you please try the following code?


objWorkBook = CreateObject("java", "com.aspose.cells.Workbook").init("C:\InductionHistoricalComparisonSpreadsheet.xlsm");

Please also note that FileFormatType is not a class but it is enumeration, probably, this is causing a problem in your original code.

If the problem still persists, then please provide us your source xlsm file.

Unfortunately that does not seem to have changed things. I downloaded the updated version, copied it to my lib folder, deleted the old jar and restarted the ColdFusion service. I then tried it with my xlsm file and a test xlsx file and got the same error. Here is the code and below that is the error. I have attached the xlsx file since it is much smaller than the xlsm file.


objWorkBook = CreateObject(“java”, “com.aspose.cells.Workbook”).init(“C:\Book1.xlsx”);

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 D:\inetpub\wwwroot\Projects\RRS\DeleteMe.cfm: line 62
60 : —>
61 :
62 : objWorkBook = CreateObject(“java”, “com.aspose.cells.Workbook”).init(“C:\Book1.xlsx”);
63 :
64 :

Browser Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5
Remote Address 127.0.0.1
Referrer
Date/Time 29-Jun-12 09:34 PM
Stack Trace
at cfDeleteMe2ecfm1301964832.runPage(D:\inetpub\wwwroot\Projects\RRS\DeleteMe.cfm:62) at cfDeleteMe2ecfm1301964832.runPage(D:\inetpub\wwwroot\Projects\RRS\DeleteMe.cfm:62)

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at coldfusion.runtime.java.JavaProxy.CreateObject(JavaProxy.java:166)
at coldfusion.runtime.java.JavaProxy.invoke(JavaProxy.java:80)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2360)
at cfDeleteMe2ecfm1301964832.runPage(D:\inetpub\wwwroot\Projects\RRS\DeleteMe.cfm:62)
at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:231)
at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:416)
at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65)
at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:363)
at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48)
at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
at coldfusion.filter.PathFilter.invoke(PathFilter.java:87)
at coldfusion.filter.LicenseFilter.invoke(LicenseFilter.java:27)
at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:70)
at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:74)
at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46)
at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:53)
at coldfusion.CfmServlet.service(CfmServlet.java:200)
at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
at jrun.servlet.FilterChain.doFilter(FilterChain.java:86)
at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)
at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
at jrun.servlet.FilterChain.doFilter(FilterChain.java:94)
at jrun.servlet.FilterChain.service(FilterChain.java:101)
at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106)
at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:286)
at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543)
at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:203)
at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:320)
at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428)
at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:266)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
Caused by: java.lang.NoClassDefFoundError: org/dom4j/Branch
at com.aspose.cells.mf.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.(Unknown Source)
… 40 more
Caused by: java.lang.ClassNotFoundException: org.dom4j.Branch
at jrunx.util.JRunURLClassLoader.findClass(JRunURLClassLoader.java:177)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at jrunx.util.JRunURLClassLoader.loadClass(JRunURLClassLoader.java:76)
at jrunx.util.JRunURLClassLoader.loadClass(JRunURLClassLoader.java:68)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
… 44 more

Hi,

Thanks for your feedback.

I have tested your file with the following code and it is working fine, so there is no problem with file.

From your exception

Caused by: java.lang.NoClassDefFoundError: org/dom4j/Branch
Caused by: java.lang.ClassNotFoundException: org.dom4j.Branch

I think, you are missing the libraries required by Aspose.Cells for Java.

Please note, you need to add the following libs in your classpath.

  1. aspose-cells-7.2.2.1.jar
  2. bcprov-jdk16-146.jar
  3. dom4j-1.6.1.jar
  4. stax2-api-3.0.2.jar
  5. woodstox-core-asl-4.1.1.jar

You can found all of them from Major Release:

Aspose.Cells for Java 7.2.2

Let me know your feedback.

For some reason I had only copied over the aspose-cells-7.2.2.jar file. I copied over the rest of the files. I removed the apose-cells-7.2.2.jar and copied back the aspose-cells-7.2.2.1.jar and then restarted ColdFusion. I am getting this error now and assuming it is something to do with the line in there about the DocumentFactory:


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 D:\inetpub\wwwroot\Projects\RRS\DeleteMe.cfm: line 62
60 : —>
61 :
62 : objWorkBook = CreateObject(“java”, “com.aspose.cells.Workbook”).init(“C:\Book1.xlsx”);
63 :
64 :


Browser Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5
Remote Address 127.0.0.1
Referrer
Date/Time 29-Jun-12 11:01 PM
Stack Trace
at cfDeleteMe2ecfm1301964832.runPage(D:\inetpub\wwwroot\Projects\RRS\DeleteMe.cfm:62) at cfDeleteMe2ecfm1301964832.runPage(D:\inetpub\wwwroot\Projects\RRS\DeleteMe.cfm:62)

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at coldfusion.runtime.java.JavaProxy.CreateObject(JavaProxy.java:166)
at coldfusion.runtime.java.JavaProxy.invoke(JavaProxy.java:80)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2360)
at cfDeleteMe2ecfm1301964832.runPage(D:\inetpub\wwwroot\Projects\RRS\DeleteMe.cfm:62)
at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:231)
at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:416)
at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65)
at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:363)
at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48)
at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
at coldfusion.filter.PathFilter.invoke(PathFilter.java:87)
at coldfusion.filter.LicenseFilter.invoke(LicenseFilter.java:27)
at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:70)
at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:74)
at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46)
at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:53)
at coldfusion.CfmServlet.service(CfmServlet.java:200)
at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
at jrun.servlet.FilterChain.doFilter(FilterChain.java:86)
at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)
at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
at jrun.servlet.FilterChain.doFilter(FilterChain.java:94)
at jrun.servlet.FilterChain.service(FilterChain.java:101)
at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106)
at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:286)
at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543)
at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:203)
at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:320)
at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428)
at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:266)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
Caused by: org.dom4j.DocumentException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory Nested exception: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.dom4j.io.SAXReader.read(SAXReader.java:343)
at com.aspose.cells.a.c.A.a(Unknown Source)
at com.aspose.cells.a.c.A.a(Unknown Source)
at com.aspose.cells.mg.m(Unknown Source)
at com.aspose.cells.mg.a(Unknown Source)
at com.aspose.cells.mf.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.(Unknown Source)
… 40 more

Hi,

Could you try this code and let me know the results? Please make sure that all libraries are in your class path?

It could also be possible that cold fusion itself use some of these libraries and error could occur because of duplicating libraries.

  1. bcprov-jdk16-146.jar
  2. dom4j-1.6.1.jar
  3. stax2-api-3.0.2.jar
  4. woodstox-core-asl-4.1.1.jar

Anyway, please try the following code and let me know the feedback.

objWorkBook = CreateObject(“java”, “com.aspose.cells.Workbook”).init();

That code executes without any errors. All of the files are in the library path, the 5 needed for Aspose were all new files to the library and can be seen in the attached screenshot of the entire library.

Hi,

Thanks for your feedback and the screenshot.

It’s very strange that you get exception when you instantiate a workbook from an excel file when all the libraries are in a class path

I have logged this issue in our database. We will look into this issue and once the issue is resolved or we have some other update for you, we will let you know.

This issue has been logged as CELLSJAVA-40236.

For what it is worth, getting errors with ColdFusion 10 as well:


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 D:/inetpub/wwwroot/Projects/RRS/DeleteMe.cfm: line 77
75 :
76 :
77 : objWorkBook = CreateObject(“java”, “com.aspose.cells.Workbook”).init(“C:\Book1.xlsx”);
78 :
79 : <!—


Browser Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5
Remote Address 127.0.0.1
Referrer
Date/Time 30-Jun-12 02:17 PM
Stack Trace
at cfDeleteMe2ecfm1301964832.runPage(D:/inetpub/wwwroot/Projects/RRS/DeleteMe.cfm:77)
at cfDeleteMe2ecfm1301964832.runPage(D:/inetpub/wwwroot/Projects/RRS/DeleteMe.cfm:77)

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at coldfusion.runtime.java.JavaProxy.CreateObject(JavaProxy.java:166)
at coldfusion.runtime.java.JavaProxy.invoke(JavaProxy.java:80)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2432)
at cfDeleteMe2ecfm1301964832.runPage(D:\inetpub\wwwroot\Projects\RRS\DeleteMe.cfm:77)
at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:244)
at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:444)
at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65)
at coldfusion.filter.IpFilter.invoke(IpFilter.java:64)
at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:443)
at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48)
at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
at coldfusion.filter.PathFilter.invoke(PathFilter.java:112)
at coldfusion.filter.LicenseFilter.invoke(LicenseFilter.java:30)
at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:94)
at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:79)
at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46)
at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:62)
at coldfusion.CfmServlet.service(CfmServlet.java:204)
at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)
at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:414)
at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:203)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:298)
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: org.dom4j.DocumentException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory Nested exception: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.dom4j.io.SAXReader.read(SAXReader.java:343)
at com.aspose.cells.a.c.A.a(Unknown Source)
at com.aspose.cells.a.c.A.a(Unknown Source)
at com.aspose.cells.mg.m(Unknown Source)
at com.aspose.cells.mg.a(Unknown Source)
at com.aspose.cells.mf.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.(Unknown Source)
… 47 more

Hi,

Thanks for your posting and using Aspose.Cells.

We will look into this issue and update you in coming week.

Also, I have logged your comment against the issue id: CELLSJAVA-40236.

Hi,

Thanks for your posting and using Aspose.Cells for Java.

From the exception stack trace, it seems that multiple libraries of dom4j have been loaded by the server by different classloaders. Please check your server environment to make sure there is only one dom4j library be used. If there is one dom4j library in the global library path of your server, we think you can just remove the dom4j library coming along with aspose.cells.jar.

I do not see another file with that name but removing the one that comes with Aspose results in 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 D:/inetpub/wwwroot/Projects/RRS/DeleteMe.cfm: line 77
75 :
76 :
77 : objWorkBook = CreateObject(“java”, “com.aspose.cells.Workbook”).init(“C:\Book1.xlsx”);
78 :
79 : <!—


Browser Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47 Safari/536.11
Remote Address 127.0.0.1
Referrer
Date/Time 02-Jul-12 05:41 AM
Stack Trace
at cfDeleteMe2ecfm1301964832.runPage(D:/inetpub/wwwroot/Projects/RRS/DeleteMe.cfm:77)
at cfDeleteMe2ecfm1301964832.runPage(D:/inetpub/wwwroot/Projects/RRS/DeleteMe.cfm:77)

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at coldfusion.runtime.java.JavaProxy.CreateObject(JavaProxy.java:166)
at coldfusion.runtime.java.JavaProxy.invoke(JavaProxy.java:80)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2432)
at cfDeleteMe2ecfm1301964832.runPage(D:\inetpub\wwwroot\Projects\RRS\DeleteMe.cfm:77)
at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:244)
at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:444)
at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65)
at coldfusion.filter.IpFilter.invoke(IpFilter.java:64)
at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:443)
at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48)
at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
at coldfusion.filter.PathFilter.invoke(PathFilter.java:112)
at coldfusion.filter.LicenseFilter.invoke(LicenseFilter.java:30)
at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:94)
at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:79)
at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46)
at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:62)
at coldfusion.CfmServlet.service(CfmServlet.java:204)
at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)
at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:414)
at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:203)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:298)
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: java.lang.NoClassDefFoundError: org/dom4j/Branch
at com.aspose.cells.mf.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.(Unknown Source)
… 47 more
Caused by: java.lang.ClassNotFoundException: org.dom4j.Branch
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1688)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1533)
… 51 more

Hi,

Thanks for your information.

We will look into it and get back to you asap.

Also, when I read your exceptions, then they look the dom4j library issue. It is because of conflicting classes, e.g

Caused by: org.dom4j.DocumentException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory Nested exception: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory

Tells that one class object cannot be cast into the same class object, which means there are two separate classes with the similar name.

In ColdFusion 10 I found a way to get the following code to execute without error:


objWorkBook = CreateObject(“java”, “com.aspose.cells.Workbook”).init(“C:\InductionHistoricalComparisonSpreadsheet.xlsm”);

To do that what I did is I created within my webroot a directory named “lib” and within that I put in the Aspose files with the exception of the dom4 file(when I tried that dom4 file it tossed out an error similar to what was ran into in previous posts). Then I created an Application.cfc file and within that I defined a Java class path with the following line:

THIS.javaSettings = {LoadPaths = ["lib"], loadColdFusionClassPath = true, reloadOnChange = false };

For ColdFusion 9, I downloaded a free tool referred to as JavaLoader and modified the code within this forum post:

https://forum.aspose.com/t/117816


to come up with this code, which executes without issue to open up my file:


_Thread = createObject("java", "java.lang.Thread"); //using 'Thread' breaks CFB
currentClassloader = _Thread.currentThread().getContextClassLoader();

try {
// requires loadColdFusionClassPath=true param
loader = createObject("component","javaloader.JavaLoader").init(loadPaths=paths,loadColdFusionClassPath=true);
//set the current thread's context class loader as Javaloader's classloader, so dom4j doesn't die
_Thread.currentThread().setContextClassLoader(loader.getURLClassLoader());
objWorkBook = CreateObject("java", "com.aspose.cells.Workbook").init("C:\InductionHistoricalComparisonSpreadsheet.xlsm");
}
catch(Any exc) {
rethrow;
}
finally {
/*
We have to reset the classloader, due to
thread pooling.
*/

_Thread.currentThread().setContextClassLoader(currentClassloader);
}

How can I test that I can write into a pre-existing sheet named Testing? Perhaps in cells A1 and B1. My ultimate goal if I can prove this will work would be to populate cells B1 through B500 and possibly the same for columns C and D.

Hi,

It’s good to know that you were finally able to execute the Aspose.Cells code on ColdFusion.

Please see the following Java code that writes test value in A1 and B1 and then it writes test values from B2 till B500.

It writes the test values in a per-existing worksheet named Testing.

You can convert it to ColdFusion and test it. Let us know your feedback.

I have attached the source and output xlsm file and screenshot for your reference.

Java


String filePath = “F:\Shak-Data-RW\Downloads\source.xlsm”;


//Create the workbook from existing file

Workbook workbook = new Workbook(filePath);


//Access the pre-existing worksheet named testing

Worksheet worksheet = workbook.getWorksheets().get(“Testing”);


//Write test values in A1 and B1

worksheet.getCells().get(“A1”).putValue(“Test A”);

worksheet.getCells().get(“B1”).putValue(“Test A”);



//Write test values in B2 till B500

for(int i =2; i<=500; i++)

{

worksheet.getCells().get(“B” + i).putValue(“TestB” + i);

}


//Save the workbook

workbook.save(filePath + “.out.xlsm”);

Screenshot:

Thanks, everything seems to be working fine now. Here is the ColdFusion 9 code for putting the data into the sheet and ran without any issues in my test environment.


<cfset arrayAppend(paths, directory & “/” & name)>

_Thread = createObject(“java”, “java.lang.Thread”); //using ‘Thread’ breaks CFB
currentClassloader = _Thread.currentThread().getContextClassLoader();

try {
// requires loadColdFusionClassPath=true param
loader = createObject(“component”,“javaloader.JavaLoader”).init(loadPaths=paths,loadColdFusionClassPath=true);
//set the current thread’s context class loader as Javaloader’s classloader, so dom4j doesn’t die
_Thread.currentThread().setContextClassLoader(loader.getURLClassLoader());
objWorkBook = CreateObject(“java”, “com.aspose.cells.Workbook”).init(“C:\InductionHistoricalComparisonSpreadsheet.xlsm”);
objWorkSheet = objWorkBook.getWorksheets().get(“Raw Data”);
// Populate just A1 and B1
// objWorkSheet.getCells().get(“A1”).putValue(“Test A”);
// objWorkSheet.getCells().get(“B1”).putValue(“Test A”);
// Populate F3 through F25
for(i=3; i <= 25; i++) {
objWorkSheet.getCells().get(“F#i#”).putValue(“TestB#i#”);
}

objWorkBook.save(“C:\InductionHistoricalComparisonSpreadsheet.out.xlsm”);
}
catch(Any exc) {
rethrow;
}
finally {
/*
We have to reset the classloader, due to
thread pooling.
*/

_Thread.currentThread().setContextClassLoader(currentClassloader);
}

Hi,

That’s great. Thanks for sharing the ColdFusion code example, it will be helpful for other forum members.

If you encounter any other problem, please feel free to post, we will be glad to help you.