develooper Front page | perl.beginners | Postings from January 2002

Win32::OLE and Excel questions

Thread Next
From:
Murphy, Land
Date:
January 4, 2002 11:14
Subject:
Win32::OLE and Excel questions
Message ID:
3C1E7DE94919AA46B8B13100DA3F5A6804D068BE@lrd1exc2.abcbs.net
I can't seem to find any real documentation on getting the Excel parsing
stuff to work like I expect.  
Here is my script--copied and modified from an example.  I've looked
throught the win32::ole module and can't find any serious
documentation on things like -- 

my $date = $Sheet->Cells($row,$col)->{'Value'};

-- what other options do I have besides Value for example.  For this
particular instance, the value comes back in a non-date format
which doesn't help me much.

Any help appreciated -- especially documentation.  I don't mind figuring
this out myself, but I can't tell where to go to find the info I need.



--------------------------------------------------------
use strict;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';

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

# get already active Excel application or open new
my $Excel = Win32::OLE->GetActiveObject('Excel.Application')
    || Win32::OLE->new('Excel.Application', 'Quit');  

# open Excel file
my $Book = $Excel->Workbooks->Open("C:\\DW_Enhancement_Master.xls"); 

# You can dynamically obtain the number of worksheets, rows, and columns
# through the Excel OLE interface.  Excel's Visual Basic Editor has more
# information on the Excel OLE interface.  Here we just use the first
# worksheet, rows 1 through 4 and columns 1 through 3.

# select worksheet number 1 (you can also select a worksheet by name)
my $Sheet = $Book->Worksheets(1);

foreach my $row (1..104)
{
 foreach my $col (1..9)
 {
  # skip empty cells
  next unless defined $Sheet->Cells($row,$col)->{'Value'};

 # print out the contents of a cell  
  if ($col == 1)	{  
   my $date = $Sheet->Cells($row,$col)->{'Value'};
   print "Project Date is ". $date."\n"; 
   		   	}   
 }
}

# clean up after ourselves
$Book->Close;

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About