23.4. Win32::OLE::VariantAll automation data has to be coerced into a special type called a Variant. Most of the time, you don't need to worry about explicit type coercion. You just provide your scalar data, and the magic of automation takes care of the rest. However, there are times when you want to control the exact type of data you're sending to the automation server. The Win32::OLE::Variant module provides access to the Variant data type and lets you control exactly how the data is represented. A Variant is an OLE data structure that contains a type field and a data field. The flags are implemented in Perl (as are many constants) as subroutines that return an integer value. The following table lists the Variant type flags, along with a brief description of each:
To convert data to a specific Variant type, create a variant object with either the new constructor method or the convenience function Variant: $vnt = Win32::OLE::Variant->new(type, data); $vnt = Variant(type, data); For example, to force a string to be interpreted as a date, create a Variant object and set it to the VT_DATE type: $dt = Variant(VT_DATE, "August 24, 1970"); # Create an explicit data type $sheet->Cells(1,1)->{Value} = $dt; # Set it to a spreadsheet cell 23.4.1. Win32::OLE::Variant MethodsThe following methods are defined by Win32::OLE::Variant for working with Variant data types.
$vnt->As(type) Takes a type flag argument and converts the Variant object to the supplied type before converting it to a Perl value.
$vnt->ChangeType(type) Takes a type flag argument and converts the Variant object (in place) to the supplied type. Copyright © 2002 O'Reilly & Associates. All rights reserved. |
|