| Previous | Next
Automation Methods and PropertiesOnce you have created an automation object, you can use its methods or adjust its properties as you require. Automation methods are implemented as you'd expect with the Perl object syntax: $obj->some_method(args); Automation methods can often take a number of optional parameters. You can pass $xl->WorkBooks(1)->SaveAs($f, undef, undef, undef, undef, 1, undef, undef, 1); For simplification, you can also use just the named parameters you want to set by passing a reference to a hash containing them. You can do this right in the argument list by creating an anonymous hash reference with
Properties of automation objects are accessed via hash reference notation on the object. For example:
Be aware that properties may not be writable (or even readable). Many automation objects have read-only properties and will generate an exception if you try to write to them. You'll need to consult the documentation for the object to find out which properties you can safely set. You can enumerate the properties of an automation object using the normal methods for enumerating hashes, which are
Win32::OLE MethodsWin32::OLE defines a couple of its own methods for dealing with the automation interface. These are not automation-defined methods, although they look the same. If a given method is not defined in Win32::OLE, the method call is dispatched to the automation object. If the method doesn't exist there, you will get an OLE error. The following methods are defined by Win32::OLE.
$obj->Invoke(method, args) This object method calls the given
Win32::OLE->LastError( ) This class method returns the last OLE error. In a numeric context, the error number is returned, while in a string context, the error message is returned.
Win32::OLE->QueryObjectType($obj) This class method returns the type of object queried ( Win32::OLE FunctionsThe following functions are defined by Win32::OLE. They are not exported by default.
in($coll) Returns a list of all the members of a collection referenced by the collection object
valof($obj) Dereferences an automation object (
with($obj, property1 => value1, ...) Sets the values of multiple properties on an object ( Win32::OLE Class VariablesThe Win32::OLE module defines certain class variables that set default behavior for automation usage:
|