JavaScript Instance tutorial OLE Automation (6)

Source: Internet
Author: User
Tags implement ole variable
Tutorial using OLE Automation in JavaScript

6. How to improve the performance of the script program

Since we are dealing with heavy object models (such as Word.Application) and application instances, it is important to note that the system's resources are shown. Once we have finished processing the application instance, we have to remove it to erase the object's instance from memory. There is only one way to implement it in JScript, which is the Quit () method of the Application object, and here's an example:

var wdapp = new ActiveXObject ("Word.Application");

Wdapp.quit (); Tidy up

In Visual Basic, unlike JScript and VBScript, setting an object variable to null does not erase memory. Also, if there are no other references to this object, such an assignment will cause the application to shut down. Unfortunately, in JScript we have to use the Quit () method to clear the object from memory when we have already used it. Setting a variable to a zero-length string or being empty is just a good exercise, and it does not erase memory.

Place a point at least code in the tutorial a procedure call has to be executed in the background. The best solution is to localize the cache object reference. In a nutshell, this technique can be applied to objects as well as automation objects. Here's a look at the script fragment:


var Exapp = new ActiveXObject ("Excel.Application");

Exapp.workbooks (1). Worksheets (1). Cells (1, 1). Value = "A-Cell";

Exapp.workbooks (1). Worksheets (1). Cells (1, 2). Value = "Second Cell";

Exapp.workbooks (1). Worksheets (1). Cells (1, 3). Value = "Third Cell";

Exapp.workbooks (1). Worksheets (1). Cells (1, 4). Value = "Fourth Cell";

Exapp.workbooks (1). Worksheets (1). Cells (1, 5). Value = "Fifth Cell";


The following code illustrates a more efficient way to implement:

var Exapp = new ActiveXObject ("Excel.Application");

var exwbook = exapp.workbooks (1). Worksheets (1);

Exwbook.cells (1, 1). Value = "A-Cell";

Exwbook.cells (1, 2). Value = "Second Cell";

Exwbook.cells (1, 3). Value = "Third Cell";

Exwbook.cells (1, 4). Value = "Fourth Cell";

Exwbook.cells (1, 5). Value = "Fifth Cell";

Related Article

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.