Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Using Win32:OLE on Excel

by cacharbe (Curate)
on Jul 01, 2002 at 18:08 UTC ( [id://178631]=note: print w/replies, xml ) Need Help??


in reply to Using Win32:OLE on Excel

Read this node. Everyting a growing monk needs to fulfill his daily allowance of OLE programming with Excel.

More specifically, don't create a new sheet, set :

my $Sheet = $Excel->{ActiveSheet};
and you should be able to modify the last row, last column section in the tutorial to work within a given selection, vs. on a given sheet.

Update::

'course, you don't necessarily have to work with that chunk of code, since in this case the Application->Selection object returns a Range object, so you could always just do this:

use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; use Win32::OLE::Variant; use Win32::OLE::NLS qw(:LOCALE :DATE); $Win32::OLE::Warn = 3; my $Excel = Win32::OLE->GetActiveObject('Excel.Application') or die "Ain't gonna work without an open worksheet\n"; my $Sheet = $Excel->{ActiveSheet}; my $array = $Excel->Selection->{Value}; foreach my $cell(@{$array}){ print $cell->[0]."\n"; }
C-.

---
Flex the Geek

Replies are listed 'Best First'.
Re: Re: Using Win32:OLE on Excel
by connerz (Initiate) on Jul 01, 2002 at 19:41 UTC
    Thanks for your prompt answer, that did the trick. I also read that node you pointed out. Out of curiosity, how would one, given a set range of rows (say 7 - 21) get the Range object. The msdn docs gave a discrete set of rows but not much info on a contiguous range of rows. Thanks again.. Geoff
      That depends. *grin*

      If you know the Columns involved, then:

      my $Range = $Sheet->Range($col.$startrow.":".$col.$endrow);

      or if you just want an entire column:
      my $Range = $Sheet->Columns($colletter);
      or if you just want an entire row:
      my $Range = $Sheet->Rows($rownumber);

      There are, of course, a million ways to do it.

      C-.

      ---
      Flex the Geek

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-03-28 11:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found