Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: A simple read of XLSX into Perl

by McA (Curate)
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

Hi,

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
McA


Comment on Re: A simple read of XLSX into Perl
Select or Download Code
Re^2: A simple read of XLSX into Perl
by gadi99 (Initiate) on Feb 26, 2013 at 22:32 UTC
    UPDATE:

    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:\readexcel.pl Win32::OLE(0.1709) error 0x800a03ec in METHOD/PROPERTYGET "Range" at E:\readexcel.pl line 9

    Is there something wrong with my OLE…?

      Hi,

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

      Try "A1" instead.

      J.C.

      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!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (12)
As of 2014-09-30 12:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (366 votes), past polls