Link to home
Start Free TrialLog in
Avatar of Jerry_Pang
Jerry_Pang

asked on

cfobject with excel.application error - java.lang.NoSuchMethodException.

An exception occurred when instantiating a Com object.  
The cause of this exception was that: java.lang.NoSuchMethodException.  
 
The Error Occurred in D:\wwwroot\ALLWEB\temp\sql_export.cfm: line 53
 
51 :         CLASS="Excel.Application"        
52 :         NAME="objExcel"        
53 :         TYPE="COM">  
54 :   </CFCATCH>
55 : </CFTRY>

 
********************************

code snipplet -
<!--- Try to connect to the Excel application object --->
<CFTRY>    
    <!--- If it exists, connect to it --->    
    <CFOBJECT        
        ACTION="CONNECT"        
        CLASS="Excel.Application"        
        NAME="objExcel"        
        TYPE="COM">  
  <CFCATCH>    
    <!--- The object doesn't exist, so create it --->    
    <CFOBJECT        
        ACTION="CREATE"        
        CLASS="Excel.Application"        
        NAME="objExcel"        
        TYPE="COM">  
  </CFCATCH>
</CFTRY>


************
why is this? i have  excel xp.
dunno if i should register the excel COM through "regsvr32 fullpath_and_objectName"
i dont now the objectName.
whats wrong with this? why do i get this error?? how do i fix this?
ASKER CERTIFIED SOLUTION
Avatar of jyokum
jyokum
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If u havent got the updater3 installed - then first do it - as CFMX has some problems with COM object.

also ur server needs to have EXCEL installed on it - so u can instantiate it on SERVER.

u can use CLASSID as given above by jyokum
OR
for more details - refer to www.cfcomet.com/excel/ 

K'Rgds
Anand
Avatar of Jerry_Pang
Jerry_Pang

ASKER

thats where i got the file.

im having trouble running it.
this is the edited format...
now i have a new problem..
will post a new question - how to export from SQL query to excel - no 'COM' - objects please.

An exception occurred when accessing a Com object field.  
The cause of this exception was that: coldfusion.runtime.CfJspPage$ComplexObjectException: Complex object types cannot be converted to simple values..  

 
The Error Occurred in D:\wwwroot\ALLWEB\temp\outx.cfm: line 56
 
54 :
55 : <!--- Open and activate the workbook --->
56 : <CFSET objBook = objBooks.Open(File)>
57 : <CFSET objBook.Activate()>
58 :             

 


<!--- Set the Excel file to dump the query to --->
<!--- <CFSET File = "#ExpandPath(".")#\ExcelFile.xls"> --->
For a local Excel application, use:

<!--- Try to connect to the Excel object --->
<CFTRY>
    <!--- If it exists, connect to it --->
    <CFOBJECT ACTION="CONNECT" CLASS="{00020812-0000-0000-C000-000000000046}" NAME="objExcel" TYPE="COM">
  <CFCATCH>
    <!--- The object doesn't exist, so create it --->
    <CFOBJECT ACTION="CREATE" CLASS="{00020812-0000-0000-C000-000000000046}" NAME="objExcel" TYPE="COM">
  </CFCATCH>
</CFTRY>

<!--- Create the ADO objects --->
<CFOBJECT ACTION="CREATE" CLASS="ADODB.Connection" NAME="oConn" TYPE="COM">
<CFOBJECT ACTION="CREATE" CLASS="ADODB.Recordset" NAME="oRst" TYPE="COM">
 
<CFSET SQL = "">
<!--- Database user name --->
<CFSET UserName = "****">
<!--- Database password --->
<CFSET Password = "****">
<!--- Datasource name --->
<CFSET Datasource = "****">

<!--- Get the workbooks collection --->
<CFSET objBooks = objExcel.Workbooks>

<!--- Open and activate the workbook --->
<CFSET objBook = objBooks.Open(File)>
<CFSET objBook.Activate()>
            
<!--- Get the sheets collection --->
<CFSET objSheets = objBook.WorkSheets>

To access a numeric index of a sheet, use:

<!--- Get the first sheet --->
<CFSET objSheet = objSheets.Item(Val(1))>

OR, to access a sheet by it's name, use:

<!--- Get a named sheet --->
<CFSET objSheet = objSheets.Item("Sheet1")>

<!--- Open the ADO connection and fetch the data --->            
<CFSET oConn.Open(Datasource, UserName, Password, -1)>
<CFSET oRst.open(SQL, oConn, 3, 1, 1)>

<!--- Create the range and copy the records from ADO --->
<CFSET objRange = objSheet.Range("A1")>
<CFSET objRange.CopyFromRecordset(oRst)>

<!--- Save the file --->
<CFSET objSheet.SaveAs(File, Val(1))>

<!--- Kill the ADO and Excel objects --->
<CFSET oRst.close()>
<CFSET oConn.close()>
<CFSET objBook.Close()>      

there r tags available on this [export from CF - excel]

but they involve the use of COM object

u can try using this piece of code

<CFSETTING ENABLECFOUTPUTONLY="yes">

<CFSET TAB=CHR(9)>

<CFQUERY NAME="get_Data" DATASOURCE="Deg">
      SELECT username,EMail,
      FROM   Tbl_Data
</CFQUERY>

<CFHEADER NAME="Content-Disposition" VALUE="inline; filename=export.xls">
<CFCONTENT TYPE="application/msexcel">

<CFOUTPUT QUERY="get_Data">
#Currentrow##TAB##username##TAB##EMail##chr(13)#
</CFOUTPUT>

K'Rgds
Anand
oh i see, basically they are just the same?
they both use COM object?

oops sory
[quote]will post a new question - how to export from SQL query to excel - no 'COM' - objects please.[/quote]
Related to sql to excel
https://www.experts-exchange.com/questions/20701040/request-Please-edit-post-asap.html 

anand, post you comments there again.