ActiveXObject 對象

ActiveXObject 對象

Visual Studio 2005

此對象提供自動化對象的接口。

function ActiveXObject(ProgID : String [, location : String])
ProgID

必選。形式爲“serverName.typeName”的字符串,其中 serverName 是提供對象的應用程序的名稱,typeName 是要創建的對象的類型或類。

location

可選項。要在其中創建對象的網絡訪問器的名稱。

通常,自動化服務器會提供至少一種對象。例如,字處理應用程序可能會提供應用程序對象、文檔對象和工具欄對象。

以下代碼通過調用 ActiveXObject 對象構造函數來啓動應用程序(在這種情況下爲 Microsoft Excel 工作表)。ActiveXObject 允許您在代碼中引用應用程序。使用下面的示例,您可以使用對象變量 ExcelSheet 和其他 Excel 對象(包括應用程序對象和 ActiveSheet.Cells 集合)來訪問新對象的屬性和方法。

// Declare the variables
var Excel, Book;

// Create the Excel application object.
Excel = new ActiveXObject("Excel.Application");

// Make Excel visible.
Excel.Visible = true;

// Create a new work book.
Book = Excel.Workbooks.Add()

// Place some text in the first cell of the sheet.
Book.ActiveSheet.Cells(1,1).Value = "This is column A, row 1";

// Save the sheet.
Book.SaveAs("C:\\TEST.XLS");

// Close Excel with the Quit method on the Application object.
Excel.Application.Quit();

若要在遠程服務器上創建對象,只能在關閉 Internet 安全機制時完成。您可以通過將計算機的名稱傳遞到 ActiveXObjectservername 參數在遠程網絡計算機上創建對象。該名稱與共享名的計算機名部分相同。對於名爲“\\MyServer\public”的網絡共享,servername 爲“MyServer”。此外,您可以使用 DNS 格式或 IP 地址來指定 servername

以下代碼返回在名爲“MyServer”的遠程網絡計算機上運行的 Excel 實例的版本號:

function GetAppVersion() {
   var Excel = new ActiveXObject("Excel.Application", "MyServer");
   return(Excel.Version);
}

如果指定的遠程服務器不存在或者找不到,則會出錯。

ActiveXObject 對象不具有任何內部屬性或方法;它允許您訪問自動化對象的屬性和方法。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章