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

RE: Win32::OLE and Excel questions

Thread Previous
From:
Hanson, Robert
Date:
January 4, 2002 11:43
Subject:
RE: Win32::OLE and Excel questions
Message ID:
11A304418ECBAB498FBF10ABCEA5E499D1CBF9@hq2kax1.nj.aptegrity.com
There isn't any docs with Win32::OLE for a good reason... the
methods/properties depend on the OLE/COM object you are using.  I suggest
poking around Microsoft's site to see if there is any documentation on their
objects, or use the OLE browser that comes with the ActivePerl docs (look
under OLE, then Browser in the left hand pane).

Using the OLE browser you can see the properties/methods available by doing
this...

1. Select "Microsoft Excel 9.0 Object Library" in the wide window.
2. Select "Worksheet" in the smaller left-hand window.
3. Select "Cells" in the smaller right hand window.

That shows you this from your code:
my $date = $Sheet->Cells($row,$col)

In the bottom window it tells you that "Cells" is readonly and returns a
"Range"...

4. Select "Range" in the smaller left hand window.

The smaller right-hand window will now show all of the properties and
methods available for that object.

With any luck someone will also post a good FAQ on the web.  This question
comes up a lot, so I am sure there is stuff out there.

Rob


-----Original Message-----
From: Murphy, Land [mailto:GDMurphy@arkbluecross.com]
Sent: Friday, January 04, 2002 2:17 PM
To: 'beginners@perl.org'
Subject: Win32::OLE and Excel questions


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;

-- 
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org

Thread Previous


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