How to launch excel application from client side javascript ?
-
Sunday, October 07, 2007 1:57 PM
Hi
Everybody
I want to launch excel application from client side javascript.
I add microsoft office object library reference to project .
I used some codes:
<script language="javascript">
function runApp()
{
var excApp = new ActiveXObject("Excel.Application");
excApp.visible = true;
var excBook = excApp.Workbooks.open("c:\test.xls");
}
</script>
The following error occrs:
Microsoft JScript runtime error: Automation server can't create object.
at the line << var excApp = new ActiveXObject("Excel.Application"); >>
Pls help.
Thanks in advance
All Replies
-
Tuesday, October 09, 2007 3:30 AMModerator
Hi trandtun,
As I understand for your error message saying "Microsoft JScript runtime error: Automation server can't create object", you can try to enable ActiveX controls and plug-ins in IE according to the following steps:
Open IE -> Tools ->Internet Options -> Security -> Custom Level -> ActiveX controls and plug-ins ->Enable "Initialize and script ActiveX controls not marked as safe for scripting"
Besides, in order to avoid dead process, I suggest you to change your sample codes as follows:
Code Block<script language="javascript">
function runApp()
{
var excApp = new ActiveXObject("Excel.Application");
excApp.visible = true;
var excBook = excApp.Workbooks.open("c:\\test.xls");
idTmr = window.setInterval("Cleanup();",1000);
}
function Cleanup() {
window.clearInterval(idTmr);//“CollectGarbage” fire JScript's garbage collection to release the reference to Excel
CollectGarbage();
}</script>
Hope this helps,
Regards,
-
Monday, August 04, 2008 9:08 PM
In the above example, what's the best way to check if the Workbook has successfully been opened?
(The below simply bails... I'm just guessing at this point and having a hard time reading the msdn libraries.)var xls = new ActiveXObject ( "Excel.Application" ); var handle = null; function load_new_month_file() { var tmppath = "H:\\SPECIAL PROJECTS\\Quality Reporting Environment\\QRE_01Aug2008\\data\\"; var filename = "employeeTableAug2.xlsx"; handle = xls.Workbooks.Open(tmppath + filename, 3, false); if (handle.count > 0) { return true; } else { alert("Epic Fail. File was not opened.") return false; } } -
Wednesday, April 29, 2009 4:09 PMHello.
Try either this:
var xls = new ActiveXObject ( "Excel.Application" ); var handle = null ; function load_new_month_file() { var tmppath = "H:\\SPECIAL PROJECTS\\Quality Reporting Environment\\QRE_01Aug2008\\data\\" ; var filename = "employeeTableAug2.xlsx" ; handle = xls.Workbooks.Open(tmppath + filename, 3, false ); if ((handle != null) && (handle != undefined)) { return true ; } else { alert("Epic Fail. File was not opened." ) return false ; } }
or this:
var xls = new ActiveXObject ( "Excel.Application" ); var handle = null ; function load_new_month_file() { var tmppath = "H:\\SPECIAL PROJECTS\\Quality Reporting Environment\\QRE_01Aug2008\\data\\" ; var filename = "employeeTableAug2.xlsx" ; try{ handle = xls.Workbooks.Open(tmppath + filename, 3, false ); }
catch(e){
alert(e.description)
}}
the object "handle" which refers to the open workbook has no attribute count, so handle.count is always undefined.- Edited by p3tr Wednesday, April 29, 2009 4:17 PM couldn't decide to use null or undefined... (?!)
-
Tuesday, August 11, 2009 12:00 PMBy default, browser would not aloow to create this object. I do not want each of my customer to make this browser change.also this is browser dependent.Is there any other way to read an excell sheet at client end itself. I do not want to upload the excell to the server and read there. Instead i want to read it in client side and take the same to the server.Is there any posiblity? if so kindly provide me with samples....Thanks,Ramanan R
-
Thursday, December 09, 2010 9:45 PM
Hi trandtun,
As I understand for your error message saying "Microsoft JScript runtime error: Automation server can't create object", you can try to enable ActiveX controls and plug-ins in IE according to the following steps:
Open IE -> Tools ->Internet Options -> Security -> Custom Level -> ActiveX controls and plug-ins ->Enable "Initialize and script ActiveX controls not marked as safe for scripting"
Besides, in order to avoid dead process, I suggest you to change your sample codes as follows:
Code Block<script language="javascript">
function runApp()
{
var excApp = new ActiveXObject("Excel.Application");
excApp.visible = true;
var excBook = excApp.Workbooks.open("c:\\test.xls");
idTmr = window.setInterval("Cleanup();",1000);
}
function Cleanup() {
window.clearInterval(idTmr);//“CollectGarbage” fire JScript's garbage collection to release the reference to Excel
CollectGarbage();
}</script>
Hope this helps,
Regards,
I have been bumping my head for days because IE8 did not fire up Excel in our application. Your solution help me to get around with this issue. Thanks a lot.s

