Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: A simple read of XLSX into Perl

by McA (Priest)
on Feb 26, 2013 at 21:13 UTC ( #1020760=note: print w/replies, xml ) Need Help??

in reply to A simple read of XLSX into Perl


the line which causes trouble is:

my $Sheet -> Range ("A1") -> {Value};

That is NOT an assignment. I'm sure you forget to assign to the newly declared variable $Sheet.

EDIT: Have you looked at Read XLSX Files ?

Best regards

Replies are listed 'Best First'.
Re^2: A simple read of XLSX into Perl
by gadi99 (Initiate) on Feb 26, 2013 at 22:32 UTC

    I tried something different :

    use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; $Win32::OLE::Warn = 3; my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32: +:OLE->new('Excel.Application', 'Quit'); my $Book = $Excel->Workbooks->Open("E:\\readexcel.xlsx"); my $Sheet = $Book->Worksheets(1); my $array = $Sheet->Range("A0:C2")->{'Value'}; $Book->Close; Foreach my $ref_array (@$array) { foreach my $scalar (@$ref_array) { print "$scalar\t;" } print "\n;" }

    This time I got :

    E:\>perl E:\ Win32::OLE(0.1709) error 0x800a03ec in METHOD/PROPERTYGET "Range" at E:\ line 9

    Is there something wrong with my OLE…?

      A couple of comments. First, the post from the Anonymous Monk is correct about the column numbering. In the OLE environment, Excel's columns and rows are 1 based and 0 based. In other words, the upper left most corner cell is row 1, column 1 or A1, depending on which cell reference scheme that you're using.

      Secondly, I personally would discourage the practice of writing your code such that it takes over an active instance of Excel. For more info, check out the posts from me and davies in "use Win32::OLE::Const" not having an effect and Perl r/w Excel with OLE. (If you believe that davies and I contradict each other in those threads, I'd recommend going with what davies says since he's far more knowledgeable with both Excel and OLE.)

        Oh my goodness! I T - W O R K S ! ! ! ! My Perl is reading the XLSX. I'm going to convert to Monkeism right now. Thank you all. I'm going to read all the docs per your advise. Hooray for the monks!


      I think it may be the "A0" that is causing the problem this time.

      Try "A1" instead.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1020760]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2017-05-30 04:06 GMT
Find Nodes?
    Voting Booth?