<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>
<CFSCRIPT>
/* Open Excel in the background */
objExcel.Visible = false;
/* Disable alerts such as: 'Save this document?' */
objExcel.DisplayAlerts = false;
/* Define the workbooks object */
objWorkBook = objExcel.Workbooks;
/* Open the Excel file */
objOpenedBook = objWorkBook.Open("#Attributes.FilePath#");
/* Create a collection of all existing worksheets */
objSheets = objOpenedBook.Sheets;
/* The number of sheets in the file */
numOfSheets = objSheets.Count;
</CFSCRIPT>
I get this error:
An exception occurred when executing a Com method.
The cause of this exception was that: AutomationException: 0x80010105 - The
server threw an exception..
The error occurred in D:\Applications\LDev\Tag\ReadXLS.cfm: line 85
Called from D:\Applications\LDev\Assessment.cfm: line 84
Called from D:\Applications\LDev\Assessment.cfm: line 73
Called from D:\Applications\LDev\Assessment.cfm: line 51
Called from D:\Applications\LDev\Assessment.cfm: line 1
Called from C:\CFusionMX7\CustomTags\Layout.cfm: line 351
Called from C:\CFusionMX7\CustomTags\Layout.cfm: line 1
Called from D:\Applications\LDev\Index.cfm: line 99
Called from D:\Applications\LDev\Tag\ReadXLS.cfm: line 85
Called from D:\Applications\LDev\Assessment.cfm: line 84
Called from D:\Applications\LDev\Assessment.cfm: line 73
Called from D:\Applications\LDev\Assessment.cfm: line 51
Called from D:\Applications\LDev\Assessment.cfm: line 1
Called from C:\CFusionMX7\CustomTags\Layout.cfm: line 351
Called from C:\CFusionMX7\CustomTags\Layout.cfm: line 1
Called from D:\Applications\LDev\Index.cfm: line 99
83 : objExcel.Visible = false;
84 : /* Disable alerts such as: 'Save this document?' */
85 : objExcel.DisplayAlerts = false;
86 : /* Define the workbooks object */
87 : objWorkBook = objExcel.Workbooks;
Any one who knows what can be done to make it work??
Yes I saw this article and installed office 2003 sp2. But it still doesn?t
work.
This sentence bothers me:
We do not currently recommend or support Automation of Microsoft Office
programs from any unattended, non-interactive client program or component. For
more information, click the following article number to view the article in the
Microsoft Knowledge Base:
Hi Ken
We are using Coldfusion MX 7 (7,0,0,91690) on a windows 2003 server sp1.
The Excel version is 2003 sp2 (11.6560.6568).
When I run the code I see one Excel process that finishes when the code fails.
And it fails with this:
An exception occurred when executing a Com method.
The cause of this exception was that: AutomationException: 0x80010105 - The
server threw an exception..
The error occurred in D:\Applications\LDev\Tag\ReadXLS.cfm: line 85
Called from D:\Applications\LDev\Tag\PopUpUploadExcel.cfm: line 115
Called from D:\Applications\LDev\Tag\ReadXLS.cfm: line 85
Called from D:\Applications\LDev\Tag\PopUpUploadExcel.cfm: line 115
83 : objExcel.Visible = false;
84 : /* Disable alerts such as: 'Save this document?' */
85 : objExcel.DisplayAlerts = false;
86 : /* Define the workbooks object */
87 : objWorkBook = objExcel.Workbooks;
This mean that the connection to the Excel com object does success. But I
don?t understand why it fails on line 85 and not on line 83 which is the first
command it executes on the object.
I have tried to restart the server and then it worked!! I hope it will keep
working.
The com connection works fine
<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>
I have tried to comment some of the lines out when I execute commands on the
object.
The result is shown beneath.
<CFSCRIPT>
objExcel.Visible = false;
/*objExcel.DisplayAlerts = false; */
objWorkBook = objExcel.Workbooks;
/* objOpenedBook = objWorkBook.Open("#Attributes.FilePath#");*/
/* objSheets = objOpenedBook.Sheets;*/
/* numOfSheets = objSheets.Count;*/
</CFSCRIPT>
I think it is strange that the Visible and Workbooks does work. But the rest
does throw an error if they are used?
This is verry strange. When I do the test locally on my dev env it works.
Next, I would start using some of the new features of CFMX to make your COM
calls a little more robust. In CFMX it is possible to use java stubs to make
your calls to the msoffice programs. This can speed things up and even
sometimes cure specific method call failures. In your case, all that is needed
to do this is to replace the programID you are using in the cfobject calls from
"Excel.Application" to "Excel.Application.10". You can read about this at
http://livedocs.macromedia.com/coldfusion/7/htmldocs/00001582.htm#1148538.
Just realize for msoffice the stubs and xml file are already created for you
and ready to use.
The next enhancement is the releasecomobject function. CFMX has this function
and it will release excel.application from memory. When I use this function
call at the end of your page, I never see more than 1 instance of excel.
Without I see 2 or more.
I also see on the cfobject/create code working, never the connect. That is
probably a good thing. I would suspect that cfobject/connect could put you in
the situation where you temporarilly connect to a COM object that is about to
shutdown to be garbage collected. The developer's guide does mention putting
COM objects into the application scope as a way to make things more efficient.
You could test it. The procedure is discussed in the same chapter of the
Developer's Guide that I refered you to already.
Finally, you might consider completely moving away from COM. COM is somewhat
inefficient when called from java, as CFMX does. It also requires that you
have msoffice on the CFMX server and puts you at its mercy as changes are made
(see first paragraph). Apache has a project http://jakarta.apache.org/poi/
which replaces the calls to COM object with calls to Java objects. Often the
exact same syntax for you COM object method calls will work with POI. You
simply do a cfobject/java instead of cfobject/COM. You will probably find all
methods and properties that expect a visible window will go away with POI. So,
things like "objExcel.visble=false" and displayAlerts should not be called.
HTH
<CFSCRIPT>
fs =
createobject("java","org.apache.poi.poifs.filesystem.POIFSFileSystem");
fsSTR=createobject("java","java.io.FileInputStream");
fs.init(fsSTR.init("C:\Documents and Settings\ksmith\My
Documents\current.xls"));
//POIFSFileSystem fs = new POIFSFileSystem(new
FileInputStream("workbook.xls"));
wb = createobject("java","org.apache.poi.hssf.usermodel.HSSFWorkbook");
wb.Init(fs);
</CFSCRIPT>
<H2>number sheets: <cfoutput>#wb.getNumberOfSheets()#</cfoutput></H2>
I was starting the CF service with a domain user.
When I tried Excel.Application.10 instead of Excel.Application it worked just
fine.
Yesterday I started to look at the customtag cfx_excel which does the job
great through POI.
But I think that I will give my own version through POI i try. I think that It
will be faster than the COM version.
Thank you for your great help.
Is there a list or description of all the jar files (if any other than POI)
installed with cfmx7.
It would be nice to know what other jar files that could be used without any
work in cfmx7.
By the way it works just fine and mutch faster than the COM method.
Best regards,
Morten