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.NoSuchMethodExce ption.
The Error Occurred in D:\wwwroot\ALLWEB\temp\sql _export.cf m: 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?
The cause of this exception was that: java.lang.NoSuchMethodExce
The Error Occurred in D:\wwwroot\ALLWEB\temp\sql
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thats where i got the file.
im having trouble running it.
im having trouble running it.
ASKER
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.CfJspPa ge$Complex ObjectExce ption: Complex object types cannot be converted to simple values..
The Error Occurred in D:\wwwroot\ALLWEB\temp\out x.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(".")#\ExcelFi le.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-0000 00000046}" NAME="objExcel" TYPE="COM">
<CFCATCH>
<!--- The object doesn't exist, so create it --->
<CFOBJECT ACTION="CREATE" CLASS="{00020812-0000-0000 -C000-0000 00000046}" 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()>
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.CfJspPa
The Error Occurred in D:\wwwroot\ALLWEB\temp\out
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(".")#\ExcelFi
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
<CFCATCH>
<!--- The object doesn't exist, so create it --->
<CFOBJECT ACTION="CREATE" CLASS="{00020812-0000-0000
</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
<!--- 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##EMa il##chr(13 )#
</CFOUTPUT>
K'Rgds
Anand
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"
<CFCONTENT TYPE="application/msexcel"
<CFOUTPUT QUERY="get_Data">
#Currentrow##TAB##username
</CFOUTPUT>
K'Rgds
Anand
ASKER
oh i see, basically they are just the same?
they both use COM object?
they both use COM object?
ASKER
ASKER
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
[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
ASKER
anand, post you comments there again.
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