JavaScript function-activexobject Function

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.