tag:blogger.com,1999:blog-5824660313967021040.post3908002346040236495..comments2022-03-26T08:56:28.677-07:00Comments on cfSearching: POI Examples - Create/Read Cell CommentsUnknownnoreply@blogger.comBlogger8125tag:blogger.com,1999:blog-5824660313967021040.post-65684103983894835672008-12-16T15:07:00.000-08:002008-12-16T15:07:00.000-08:00@Murray,You are welcome! > and I called you Ben...@Murray,<BR/><BR/>You are welcome! <BR/><BR/>> and I called you Ben instead of <BR/>> Leigh!!! I had also been browsing > Ben Nadel's blog. <BR/><BR/>No problem at all. That is exactly what I figured ;-)cfSearchinghttps://www.blogger.com/profile/11564374520734454860noreply@blogger.comtag:blogger.com,1999:blog-5824660313967021040.post-52895620540044306102008-12-16T14:16:00.000-08:002008-12-16T14:16:00.000-08:00Yes, using the javaLoader getClass worked fine. Th...Yes, using the javaLoader getClass worked fine. Thanks for clearing that up.<BR/><BR/>Now it is my turn to smack my forehead....<BR/><BR/>Your suggestion of using the javaCast was correct all along! I just failed to notice that the createCell() method was used twice and I only changed the first one. That's what I get for pushing on when I should be sleeping!!!<BR/><BR/>Thanks again for your help.<BR/><BR/>Cheers,<BR/>MurrayAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-5824660313967021040.post-90430584207009194862008-12-16T13:46:00.000-08:002008-12-16T13:46:00.000-08:00@Murray,{smacks forehead} Brandon's method doe...@Murray,<BR/><BR/>{smacks forehead} <BR/><BR/>Brandon's method does work. But I forgot that it checks the built in CF classLoader. Since we are using the JavaLoader, we should check the one the JavaLoader uses. <BR/><BR/>Try this. It worked for me with MX 7:<BR/><BR/><cfscript><BR/> // get javaLoader reference<BR/> javaLoader = server[ application.myJavaLoaderKey ];<BR/> // create test workbook object<BR/> wb = javaLoader.create("org.apache.poi.hssf.usermodel.HSSFWorkbook").init();<BR/><BR/> // get the class name (without the package) ie HSSFWorkbook.class <BR/> className = listLast( wb.getClass().getName(), ".") &".class";<BR/> resourceURL = wb.getClass().getResource( className );<BR/> WriteOutput(resourceURL &"<BR>");<BR/></cfscript><BR/><BR/><I><BR/>> I used the javaCast as you <BR/>> suggested on your example script > on this page and still got the <BR/>> original error <BR/></I><BR/><BR/>I tried createCell and it did work for me with MX7. Even without the JavaLoader. What happens if you split the code into two lines?<BR/><BR/>// use javacast<BR/>row = sheet.createRow( 3 );<BR/>cell1 = row.createCell( 1 );cfSearchinghttps://www.blogger.com/profile/11564374520734454860noreply@blogger.comtag:blogger.com,1999:blog-5824660313967021040.post-69114189811902374842008-12-16T13:33:00.000-08:002008-12-16T13:33:00.000-08:00and I called you Ben instead of Leigh!!! I had als...and I called you Ben instead of Leigh!!! I had also been browsing Ben Nadel's blog. <BR/><BR/>My apologies - a senior moment, I guess.<BR/><BR/>MurrayAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-5824660313967021040.post-75252664868166186742008-12-16T12:39:00.000-08:002008-12-16T12:39:00.000-08:00Hi Ben,Now I am really confused! :-)When I ran you...Hi Ben,<BR/><BR/>Now I am really confused! :-)<BR/><BR/>When I ran your script I got<BR/><BR/>jar:file:/C:/CFusionMX7/runtime/../lib/poi-2.5.1-final-20040804.jar!/org/apache/poi/hssf/usermodel/HSSFSheet.class<BR/><BR/>ie the builtin version.<BR/><BR/>Thinking that was strange I ran the following code to test my iText jars. First, I ran an app that uses iText classes and methods that are not in the cf mx7 itext (eg pdfptable) to make sure that the javaloader was working correctly. All tested OK.<BR/><BR/>Then I ran the following script (using Brandon's code) and got the results listed below.<BR/><BR/>(Sorry about some missing < in the code below - your comment entry window wouldnt allow tags)<BR/><BR/>cffunction name="resolveResource" returnType="string"><BR/> cfset var resourceURL = getClass().getClassLoader().getResource(resource)><BR/> cfif isDefined("resourceURL")><BR/> cfreturn resourceURL><BR/> /cfif><BR/> cfreturn "could not resolve resource"><BR/>/cffunction><BR/><BR/>cfoutput><BR/><BR/>cfset resource="org/apache/poi/hssf/usermodel/HSSFSheet.class"><BR/>p>#resource#: [#resolveResource(resource)#]<BR/><BR/>cfset resource="com/lowagie/text/pdf/PdfPTable.class"><BR/>p>#resource#: [#resolveResource(resource)#]<BR/><BR/>/cfoutput><BR/><BR/>Results:<BR/><BR/>org/apache/poi/hssf/usermodel/HSSFSheet.class: [ jar:file:/C:/CFusionMX7/runtime/../lib/poi-2.5.1-final-20040804.jar!/org/apache/poi/hssf/usermodel/HSSFSheet.class]<BR/><BR/>com/lowagie/text/pdf/PdfPTable.class: [ jar:file:/C:/CFusionMX7/runtime/../lib/iText.jar!/com/lowagie/text/pdf/PdfPTable.class]<BR/><BR/>Now, my javaloaded jars are in C:\CFusionMX7\wwwroot\Sites\CFLib\cfc\javaclass and I double checked to make sure they werent in the path reported above.<BR/><BR/>Apart from all that, I used the javaCast as you suggested on your example script on this page and still got the original error (method createCell was not found).<BR/><BR/>I am using MX7.<BR/><BR/>This is strange. As a final test I tried Brandon's method on one of my own test java classes that I am javaLoading. The class is there because this works:<BR/><BR/>testObj = variables.javaLoader.create("itextTests.test1").init(); <BR/><BR/>result = testObj.echo("testing");<BR/> <BR/>WriteOutput("<BR>test1= "&result);<BR/><BR/>but when I run this:<BR/>cfset resource="itextTests/test1.class"><BR/>p>#resource#: [#resolveResource(resource)#]<BR/><BR/>I get:<BR/>itextTests/test1.class: [ could not resolve resource]<BR/><BR/>So, I just wanted to check that Brandon's method does work with javaLoaded classes and that my path "itextTests/test1.class" has the correct syntax.<BR/><BR/>Thanks,<BR/>MurrayAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-5824660313967021040.post-54476245286680372602008-12-16T07:43:00.000-08:002008-12-16T07:43:00.000-08:00> which which method Well drat. My edit did not...> which which method <BR/><BR/>Well drat. My edit did not take ;-)<BR/><BR/>LeighcfSearchinghttps://www.blogger.com/profile/11564374520734454860noreply@blogger.comtag:blogger.com,1999:blog-5824660313967021040.post-11716545070796054602008-12-16T07:35:00.000-08:002008-12-16T07:35:00.000-08:00Hi Murray,It is probably because the createCell() ...Hi Murray,<BR/><BR/>It is probably because the <A HREF="http://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFRow.html#createCell(int)" REL="nofollow">createCell()</A> method is overloaded. So CF does not know which which method to call: createCell(int) or createCell(short). Try using javacast to reduce the ambiguity. <BR/><BR/>cell1 = sheet.createRow( javacast("int", 3) ).createCell( javacast("int", 1) );<BR/><BR/>> Do you know if there is a POI <BR/>> function call to return the <BR/>> current version of the jars so I > can see what version CF is <BR/>> linking in?<BR/><BR/>An old, but very useful tip from Brandon Purcell's blog shows how to do this for any class:<BR/><BR/><A HREF="http://www.bpurcell.org/blog/index.cfm?entry=982&mode=entry" REL="nofollow">Identifying Which Jar file a class was loaded from in ColdFusion MX</A><BR/><BR/>Example using POI:<BR/><cfscript><BR/> resourceClass = "org/apache/poi/hssf/usermodel/HSSFSheet.class";<BR/> resourceURL = getClass().getClassLoader().getResource(resourceClass);<BR/> if ( IsDefined("resourceURL") ) {<BR/> WriteOutput(resourceClass &"="& resourceURL);<BR/> }<BR/> else {<BR/> WriteOutput("could not resolve resource");<BR/> }<BR/></cfscript>cfSearchinghttps://www.blogger.com/profile/11564374520734454860noreply@blogger.comtag:blogger.com,1999:blog-5824660313967021040.post-68215781889851240782008-12-16T03:16:00.000-08:002008-12-16T03:16:00.000-08:00Hi CFSearching.I am using the POI jars and when I ...Hi CFSearching.<BR/><BR/>I am using the POI jars and when I run the first example on this page I get the error "ERROR: The selected method createCell was not found. Either there are no methods with the specified method name and argument types, or the method createCell is overloaded with arguments types that ColdFusion can't decipher reliably. If this is a Java object and you verified that the method exists, you may need to use the javacast function to reduce ambiguity."<BR/><BR/>It may be that I havent created my javaloader properly. <BR/><BR/>Do you know if there is a POI function call to return the current version of the jars so I can see what version CF is linking in? iText has that functionality and I was wondering whether POI did too. I have trawled through the api docs and cant find a method. <BR/><BR/>I am using version poi-bin-3.2-FINAL-20081019<BR/><BR/>Do you know of such a method?<BR/><BR/>Thanks, Murray.Anonymousnoreply@blogger.com