.NET Framework Bookmark and Share   
 index > JScript for the .NET Framework > How to launch excel application from client side javascript ?
 

How to launch excel application from client side javascript ?

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

trandtun

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-insin 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);

//�strong>CollectGarbage�fire JScript's garbage collection to release the reference to Excel
CollectGarbage();
}

</script>

Hope this helps,

Regards,

Ji Cheng Wang - MSFT

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-insin 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);

//�strong>CollectGarbage�fire JScript's garbage collection to release the reference to Excel
CollectGarbage();
}

</script>

Hope this helps,

Regards,

Ji Cheng Wang - MSFT
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.)
varxls=newActiveXObject("Excel.Application");
varhandle=null;
functionload_new_month_file(){
vartmppath="H:\\SPECIALPROJECTS\\QualityReportingEnvironment\\QRE_01Aug2008\\data\\";
varfilename="employeeTableAug2.xlsx";
handle=xls.Workbooks.Open(tmppath+filename,3,false);
if(handle.count>0){
returntrue;
}else{
alert("EpicFail.Filewasnotopened.")
returnfalse;
}
}
Daryl Malcolm
Hi,friend.I'd like to give you some help.

Noticed that there are many people having trouble with writting good quality XHTML/CSS/JS code, we think you may have interests in the one of the services we offer(such as PSD to HTML).
You can learn more about us at:

http://xhtml.WebOutsourcingServices.com
Good luck.

wenkang
Hello.

Try either this:

var xls= new ActiveXObject( "Excel.Application" );
var handle= null ;
function load_new_month_file(){
var tmppath= "H:\\SPECIALPROJECTS\\QualityReportingEnvironment\\QRE_01Aug2008\\data\\" ;
var filename= "employeeTableAug2.xlsx" ;
handle=xls.Workbooks.Open(tmppath+filename,3,false );
if ((handle != null) && (handle != undefined)){
return true ;
}else {
alert("EpicFail.Filewasnotopened." )
return false ;
}
}


or this:

var xls= new ActiveXObject( "Excel.Application" );
var handle= null ;
function load_new_month_file(){
var tmppath= "H:\\SPECIALPROJECTS\\QualityReportingEnvironment\\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 byp3tr Wednesday, April 29, 2009 4:17 PMcouldn't decide to use null or undefined... (?!)
  •  
p3tr
By 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
eceramanan

You can use google to search for other answers

Custom Search

More Threads

• Calling into your BHO from a client script:
• how to display Time on page in asp.net 2.0 without using AJAX Control.
• Problem Call a Server-side Method From Jscript file
• Time Difference observed while using new Date() in Jscript.NET
• ActiveXObject("Scripting.FileSystemObject"); and network drives
• How to Disply image in HTML from from SQL server
• Setting Default Cursor in Express 2005
• Using cascadingDroDown Ajax control with SQL Server 2000?
• Embedded Windows Control events in Internet Explorer
• PopUp Window