[Phoenix-pm] Win32::OLE Question

Douglas E. Miles perlguy at earthlink.net
Wed May 26 12:04:43 CDT 2004


Hi All!

I'm trying to understand what is returned by the Value method called 
from a Cell object.  It looks to me like the return should be a Variant, 
but my test program below proves otherwise.  It appears that only dates 
are returned as Variants, and everything else is returned as a scalar. 
Is my above assumtion wrong, or is there some Perl Magic(TM) going on 
here?  The problem I'm trying to solve is to figure out if a number is 
in the cell.  Also, I'd just like to understand how it all works.  Any 
of you Windows guys want to give a Linux guy a hand? :)

#!/usr/bin/perl

use strict;
use warnings;

use Win32::OLE;
use Win32::OLE::Const 'Microsoft Excel';

$Win32::OLE::Warn = 3; # Die on errors.

my $spreadsheet_filename = shift;

my $excel = Win32::OLE->GetActiveObject('Excel.Application') ||
             Win32::OLE->new('Excel.Application', 'Quit');

my $workbook = $excel->Workbooks->Open($spreadsheet_filename);

my $worksheet = $workbook->Worksheets(1);

my $used_range = $worksheet->UsedRange;

my $max_row = $used_range->Rows->Count;
my $max_col = $used_range->Columns->Count;

foreach my $row (1..$max_row)
{

   foreach my $col (1..$max_col)
   {

       my $cell = $worksheet->Cells($row,$col);
print ref($cell) . ": $cell\n";
       my $value = $cell->Value;
print ref($value) . ": $value\n";

   }

}

$workbook->Close;




More information about the Phoenix-pm mailing list