Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

RE: OLE VB to Perl

by barndoor (Pilgrim)
on Jul 13, 2000 at 13:22 UTC ( #22341=note: print w/replies, xml ) Need Help??


in reply to OLE VB to Perl

I think I'm right to say your trying to read through what VB would call a collection. If this is the case you should use the Win32::OLE::Enum module. This allows you to extract a collection of objects and then iterate through them.
use strict; use Win32::OLE; # Open excel. my $excel = Win32::OLE->new("Excel.Application", 'Quit'); # Create a workbook. my $excelBook = $excel->Workbooks->Add; # Enumerate the sheets in the workbook (sheet1,sheet2,sheet3 by defaul +t). my $sheets = Win32::OLE::Enum->new($excelBook->Worksheets()); #Iterate the sheets using the All() function. foreach my $sheet ($sheets->All()) { print $sheet->name() . "\n"; }
No error handling I know but it gives you an idea and I've run this on NT4.0 with Office 98.

Replies are listed 'Best First'.
RE: RE: OLE VB to Perl
by Mike McClellan (Novice) on Jul 13, 2000 at 23:48 UTC
    Thank that was just what I was lookin' for.
    foreach $child(Win32::OLE::Enum->All($ADS)){ print $child->Name . "\n"; }
    I shall own the Win2k Active Directory!!!!

      I know that this is amazingly belated, but I've been wrestling with the same issue myself and came across this thread. There's actually an easier solution to iterating over OLE collections, and it goes a little something like this:

      use Win32::OLE 'in'; foreach $member (in $collection) { #do some stuff }

      Oddly enough, I gleaned this from the Win32::OLE docs :-). The 'in' function is not exported by default, so you need to specify it in the import list, as above.

      Again, sorry for the late reply, but hopefully this will help latecomers like myself who may stumble across this thread.

      -jehuni

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://22341]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2020-03-31 07:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    To "Disagree to disagree" means to:









    Results (180 votes). Check out past polls.

    Notices?