ЭЛЕКТРОННАЯ БИБЛИОТЕКА КОАПП |
Сборники Художественной, Технической, Справочной, Английской, Нормативной, Исторической, и др. литературы. |
19.2 Creating Automation ObjectsUnfortunately, automation is one of the areas in which the ActiveState distribution differs slightly from the libwin32 OLE module for use with the standard Perl distribution. Both distributions use the # ActiveState distribution use OLE; $obj = CreateObject OLE "Excel.Application" || die "CreateObject: $!"; # libwin32 Win32::OLE use Win32::OLE; Win32::OLE::CreateObject("Excel.Application", $obj) || die "CreateObject: $!"; The ActiveState CreateObject takes two arguments: a class type (currently, always OLE), and a ProgID (program ID) string of the object to create. When an automation server is registered on the system, it stores a CLSID (class ID), which is a token that uniquely identifies an OLE object, and a ProgID that provides a human readable way to access the CLSID. Perl does the conversion internally, so you just need to provide the ProgID. A server generally has two types of ProgIDs: one is a version-independent ProgID that typically identifies the most current version of the server, the other is a version-specific ProgID that denotes a specific application version. Here are some examples of ProgIDs that you might use: Excel.Application (Microsoft Excel Application Object) Excel.WorkSheet (Microsoft Excel Worksheet Object) Word.Document.8 (Microsoft Word Document Object, Ver 8) Word.Basic.8 (Microsoft WordBasic Object, Ver 8) You'll need to check the documentation for the automation server that you want to use in order to discover what its ProgID is. CreateObject returns a reference to the automation object if it succeeds, and The libwin32 version of Throughout this chapter, we'll be using the ActiveState syntax for our automation examples. |