ActiveXObject 对象
Visual Studio 2005
此对象提供自动化对象的接口。
function ActiveXObject(ProgID : String [, location : String])
通常,自动化服务器会提供至少一种对象。例如,字处理应用程序可能会提供应用程序对象、文档对象和工具栏对象。
以下代码通过调用 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 安全机制时完成。您可以通过将计算机的名称传递到 ActiveXObject 的 servername 参数在远程网络计算机上创建对象。该名称与共享名的计算机名部分相同。对于名为“\\MyServer\public”的网络共享,servername 为“MyServer”。此外,您可以使用 DNS 格式或 IP 地址来指定 servername。
以下代码返回在名为“MyServer”的远程网络计算机上运行的 Excel 实例的版本号:
function GetAppVersion() { var Excel = new ActiveXObject("Excel.Application", "MyServer"); return(Excel.Version); }
如果指定的远程服务器不存在或者找不到,则会出错。