WIN32::OLE excel date

C

caradomski

I need help retrieving the date from excel using the Win32::OLE pm.
here is my program...

use strict;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
$Win32::OLE::Warn = 3; # die on
errors...
my $Excel = Win32::OLE->GetActiveObject('Excel.Application')
|| Win32::OLE->new('Excel.Application', 'Quit'); # get already
active Excel
# application or
open new
my $Book = $Excel->Workbooks->Open("C:\\TMP\\test1.xls"); # open Excel
file
my $Sheet = $Book->Worksheets(1); # select
worksheet number 1
my $array = $Sheet->Range("A1:D5")->{'Value'}; # get the
contents
$Book->Close;
foreach my $ref_array (@$array) { # loop through
the array
# referenced by
$array
foreach my $scalar (@$ref_array) {
print "$scalar\t";
}
print "\n";



}


When ever the program prints a date from the excel file I get the
following results...

Win32::OLE::Variant=SCALAR(0x19f7b1c)


how do I get the program to print out 10/1/2006 ?


Please help!!!
 
C

cgrady

You need to use Win32::OLE::Variant to get the correct variant
behavior. If you don't use this module, you'll get this:

Win32::OLE::Variant=SCALAR(0x1a1aad0)

This worked fine for me:

use strict;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
use Win32::OLE::Variant;
$Win32::OLE::Warn = 3;

my $Excel = Win32::OLE->GetActiveObject('Excel.Application') ||
Win32::OLE->new('Excel.Application', 'Quit');
my $Book = $Excel->Workbooks->Open("C:\\TMP\\test1.xls");
my $sheet = $Book->Worksheets(1);
my $array = $sheet->Range("A1:D5")->{Value};
for (@$array) { for (@$_) { print defined($_) ? "$_\t" : "<undef>\t"; }
print "\n"; }
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top