IDK why that module won't work with XLSX, but the solution is to just use Win32::OLE directly. It's not that hard.
This cheatsheet is another resource I've found useful. Here is some code to open a workbook and print out the content of the first five columns as a tab separated list.
#!/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;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.