|
Every dot that you place in your script represents at least one procedure call that has to be executes in the background. The best solution is to locally cache object references. This tip applies to objects in general, and specifically to Automation objects. Take a look at the following script segment:
var exApp = new ActiveXObject("Excel.Application");
exApp.Workbooks(1).Worksheets(1).Cells(1, 1).Value = "First 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 shows how to do this in a much more efficient way:
var exApp = new ActiveXObject("Excel.Application");
var exWbook = exApp.Workbooks(1).Worksheets(1);
exWbook.Cells(1, 1).Value = "First 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";
People who read this tip also read these tips:
Look for similar tips by subject:
|