In JavaScript, The activexobject object is enabled and the reference of the automation object is returned. Usage:
Newobj = new activexobject (servername. typename [, location])
Servername is required. Provide the application of this objectProgram.
Typename is required. The type or class of the object to be created.
Location is optional. Name of the network server where the object is created.
Example:
VaR Excelsheet;
Excelapp = New Activexobject ( " Excel. Application " );
Excelsheet = New Activexobject ( " Excel. Sheet " );
BenCodeStart the application for creating an object (in this case, Microsoft Excel worksheet ). Once an object is created, it can be referenced in the Code with the defined object variable. In the following example, the object variable excelsheet is used to access the attributes and methods of the new object and other Excel objects, including the application object and the activesheet. cells set.
// Make Excel visible through the Application object.
Excelsheet. application. Visible = true;
// Place some text in the first cell of the table.
Excelsheet. activesheet. cells (1, 1). value = "this is column A, Row 1 ";
// Save the table.
Excelsheet. saveas ("C :\\ test. xls ");
// Use the quit method of the Application object to close the Excel file.
Excelsheet. application. Quit ();
You can create an object on the remote server only when Internet security is disabled. To create an object on a remote network computer, you can pass the name of the computer to the servername parameter of activexobject. The name is the same as the machine name part of the shared name. For example, the share name is"\ Myserver \ public"Network, servername is" myserver ". In addition, you can specify servername in DNS format or IP address.
The following code returns the version number of an Excel instance running on a remote network computer named "myserver:
Function Getappversion (){
VaR Xlapp = New Activexobject ( " Excel. Application " , " Myserver " );
Return (Xlapp. version );
}
Example 2:
Code
VaR FSO = New Activexobject ( " Scripting. FileSystemObject " );
VaR DRV = FSO. getdrive ( " C: " );
VaR Is_ready = DRV. isready;
VaR Available_space = (DRV. availablespace / (1024x1024*1024). tofixed (1 );
VaR Free_space = (DRV. freespace / (1024x1024*1024). tofixed (1 );
VaR Total_size = (DRV. totalsize / (1024x1024*1024). tofixed (1 );
If the specified remote server does not exist or cannot be found, an error will occur.