Hello: I'm new to Perl and Perlmonks. I've been doing a lot of reading to prepare for an application (in Windows) in which I want to extract values from an Excel spreadsheet. Through some reading I've been able to get ideas about code fragments that seem to do what I need. However, I'm stuck on being able to access the values extracted from a spreadsheet using function Range. Here's the code:

#!/usr/bin/perl use strict; use warnings; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; $Win32::OLE::Warn = 3; # die on errors. +.. my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); # get already ac +tive Excel # application or + open new #my $Book = $Excel->Workbooks->Open("C:\\DOCUMENTS\\test.xls"); # open + Excel file my $Book = $Excel->Workbooks->Openmy $Sheet = $Book->Worksheets(1); + # select worksheet number 1 my $array = $Sheet->Range("A1:B10")->{'Value'}; # get the conte +nts $Book->Close;
I have not found a way to get the individual values out of $array. Everything works OK if the range is a single value, like "A1". However, when I change the range to something like ("A1:B10") I get errors or senseless data.

I suspect that I'm not indexing $array correctly, but I've not been able to figure out why, in spite of hours of searching through tutorials.

I would appreciate any help a more experienced monk could give as to how I can get to the individual values that I have extracted from the spreadsheet into $array.

Many thanks, and sorry about the long post.

Ralph


In reply to How can I access the values of an "array" extracted using Range by ralph

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.