in reply to Re: Excel file data - mail
in thread Excel file data - mail
#!/usr/bin/perl -w use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; use Win32::OLE::Variant; $Win32::OLE::Warn = 3; # die on errors. +.. my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32: +:OLE->new('Excel.Application', 'Quit'); # get already active Excel o +r create new one as appropriate $Excel->{'Visible'} = 1; # see what's going on if you want my $Book = $Excel->Workbooks->Open('C:\somefile.xlsx'); # open Excel f +ile -- requires explicit DOS path my $Sheet = $Book->Worksheets('Sheet1'); # tab name or sheet number (f +rom 1) my $lastrow = $Sheet->UsedRange->Find({What=>"*",SearchDirection=>xlPr +evious,SearchOrder=>xlByRows})->{Row}; for my $row (1..$lastrow) { foreach my $col (qw(A B C D E)) { print $Sheet->Range("$col$row")->{'Value'},"\t"; # range is co +lumn letter, row number; can also be the target of an assignment } print "\n"; } $Book->close;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Excel file data - mail
by Marshall (Canon) on Aug 04, 2016 at 15:20 UTC |