I am new Perl and programming in general, I'm trying to use Perl to automate some Excel task. I have read through most of the Ole questions and answer on here and it just confuses me. Here's what I am trying to do, I found an example that will work for what I am trying to do but I dont know what all the brackets [] does to the scalar variable $mydata. Because I am reading in data and storing it into an array, how would I need to change the code in order for it to work with an array? Or how would I need to read in the file in order to store it in the same way this scalar variable is written? Thanks in advance for any help. I am trying to learn but there is just soo much to learn, I feel overwhelmed.
# This is the code that works $mydata = [["Item", "Category", "Price"], ["Nails", "Hardware", "5.25"], ["Shirt", "Clothing", "23.00"]]; # Write all the data at once... $rng = $xlBook->ActiveSheet->Range("A1:C7"); $rng->{Value} = $mydata; # This is my code that doesn't work because I changed it to an array. @mydata = ("Item", "Category", "Price", "Nails", "Hardware", "5.25", "Shirt", "Clothing", "23.00"); # Write all the data at once... $rng = $xlBook->ActiveSheet->Range("A1:C7"); $rng->{Value} = @mydata;
Here is the full working code if you want to see it:
use Win32::OLE; # Start Excel and make it visible $xlApp = Win32::OLE->new('Excel.Application'); $xlApp->{Visible} = 1; # Create a new workbook $xlBook = $xlApp->Workbooks->Add; # Our data that we will add to the workbook... $mydata = [["Item", "Category", "Price"], ["Nails", "Hardware", "5.25"], ["Shirt", "Clothing", "23.00"], ["Hammer", "Hardware", "16.25"], ["Sandwich", "Food", "5.00"], ["Pants", "Clothing", "31.00"], ["Drinks", "Food", "2.25"]]; # Write all the data at once... $rng = $xlBook->ActiveSheet->Range("A1:C7"); $rng->{Value} = $mydata; print "All done.";
Thanks, Paul

In reply to OLE write to Excel by NewMonk2Perl

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.