For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > August 2005 > Win32::OLE question(s)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Win32::OLE question(s)
Tim

2005-08-31, 3:56 am

Hello.

The following code produces the output below. The first column should
be a date. This happens whether the "valof" function is used or not.
Anyone have any Variant tricks?

Thanks.
Tim

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:\\orders.xls"); # open Excel file
my $Sheet = $Book->Worksheets(2); # select
worksheet number 1
print "SHEET: ", $Sheet->Name, "\n";

my $array = $Sheet->Range("G4:H12")->{'Value'}; # get the contents

$Book->Close;
foreach my $ref_array (@$array) { # loop through the array
foreach my $scalar (@$ref_array) {
print valof($scalar),"\t";
}
print "\n";
}

SHEET: Inventory
Order By Qty
Win32::OLE::Variant=SCALAR(0x1a0d108) 400
Win32::OLE::Variant=SCALAR(0x1a10310) 84
Win32::OLE::Variant=SCALAR(0x1a102f8) 100
Win32::OLE::Variant=SCALAR(0x1a102e0) 196
Win32::OLE::Variant=SCALAR(0x1a0d108) 100
Win32::OLE::Variant=SCALAR(0x1a10310) 1
Win32::OLE::Variant=SCALAR(0x1a102f8) 100
Win32::OLE::Variant=SCALAR(0x1a102e0) 200

Luke Bakken

2005-08-31, 6:55 pm

Tim wrote:
> Hello.
>=20
> The following code produces the output below. The first column should
> be a date. This happens whether the "valof" function is used or not.
> Anyone have any Variant tricks?
>=20
> Thanks.
> Tim


Read up on the Range property and Cells property.

http://msdn.microsoft.com/library/d...y/en-us/vbaxl1=
1
/html/xlproCells1_HV03076630.asp

use strict;
use Win32::OLE qw/in with/;

my $Excel =3D Win32::OLE->GetActiveObject('Excel.Application') ||
Win32::OLE->new('Excel.Application', 'Quit');
my $Book =3D $Excel->Workbooks->Open("C:\\orders.xls");
my $Sheet =3D $Book->Worksheets(2);

for my $cell (in $Sheet->Range("G4:H12"))
{
print "Cell has value ", $cell->Value, "\n";
}
$Book->Close;
Luke Bakken

2005-08-31, 6:55 pm

Bakken, Luke wrote:
> Tim wrote:
>=20
> Read up on the Range property and Cells property.
>=20
>

http://msdn.microsoft.com/library/d...y/en-us/vbaxl1=
1
> /html/xlproCells1_HV03076630.asp
>=20
> use strict;
> use Win32::OLE qw/in with/;
>=20
> my $Excel =3D Win32::OLE->GetActiveObject('Excel.Application') ||
> Win32::OLE->new('Excel.Application', 'Quit');
> my $Book =3D $Excel->Workbooks->Open("C:\\orders.xls");
> my $Sheet =3D $Book->Worksheets(2);
>=20
> for my $cell (in $Sheet->Range("G4:H12"))
> {
> print "Cell has value ", $cell->Value, "\n";
> }
> $Book->Close;



That should be:

for my $cell (in $Sheet->Range("G4:H12")->Cells)
Timothy Johnson

2005-08-31, 6:55 pm


You should be able to use the Win32::OLE::Variant module to extract the
date.

Do a 'perldoc Win32::OLE::Variant' and check out the Date() method.


-----Original Message-----
From: Tim [mailto:timlhunt@mindspring.com]=20
Sent: Tuesday, August 30, 2005 2:13 PM
To: beginners@perl.org
Subject: Win32::OLE question(s)

Hello.

The following code produces the output below. The first column should=20
be a date. This happens whether the "valof" function is used or not.=20
Anyone have any Variant tricks?

<snip>

SHEET: Inventory
Order By Qty
Win32::OLE::Variant=3DSCALAR(0x1a0d108) 400
Win32::OLE::Variant=3DSCALAR(0x1a10310) 84
Win32::OLE::Variant=3DSCALAR(0x1a102f8) 100
Win32::OLE::Variant=3DSCALAR(0x1a102e0) 196
Win32::OLE::Variant=3DSCALAR(0x1a0d108) 100
Win32::OLE::Variant=3DSCALAR(0x1a10310) 1
Win32::OLE::Variant=3DSCALAR(0x1a102f8) 100
Win32::OLE::Variant=3DSCALAR(0x1a102e0) 200

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com