Have you considered Excel::Template? It sounds like your problem would be solved by something that looks like:
use Excel::Template; my $template = Excel::Template->new( file => \*DATA, ); my @data; for ($j = 1; $j <= $#model; $j++) { push @data, { device_model => $model[$j], devices_per_model => $device_per_model, devices_per_variant => $devicesPerVariant[$j], model_variant_processor => $processor[$j], device_memory => $memory[$j], device_software => $softwareVersion[$j], }; } $template->param( data => \@data, ); $template->write_to_file( "somefile.xls" ); __DATA__ <workbook> <worksheet> <row> <cell>Equipment Model</cell> <cell>Devices Per Model</cell> <cell>Devices Per Variant</cell> <cell>Model Variant Processor</cell> <cell>Device Memory</cell> <cell>Device Software</cell> </row> <loop name="data"> <row> <cell><var name="equipment_model"/></cell> <cell><var name="devices_per_model"/></cell> <cell><var name="devices_per_variant"/></cell> <cell><var name="model_variant_processor"/></cell> <cell><var name="device_memory"/></cell> <cell><var name="device_software"/></cell> </row> </loop> </worksheet> </workbook>
Now, let me explain how this works. Instead of writing to your Excel file by hand with Spreadsheet::WriteExcel, you specify your layout using a template (that just happens to be in XML), pass it your data structure, and Excel::Template will convert that into the appropriate S::WE calls. (Yes, Excel::Template uses Spreadsheet::WriteExcel under the covers.)

You have to convert your current data structure, which is a bunch of parallel arrays, into an array of hashes for the E::T loops to work correctly. This is the same data structure that HTML::Template, PDF::Template, and Template Toolkit all use. (By the way, this is a better data structure to use throughout your program, because it's more robust and all the data about a given thing is kept in one place - nothing can get out of sync.) That's what the @data array is for. Then, you specify your template, which is pretty self-explanatory.

Now, here's the major benefit of using Excel::Template vs. directly using S::WE. Let's say you wanted to make a whole section bold. Just put the whole section in <bold> tags. Or, let's say you wanted to add more items, or maybe another worksheet. Just modify the template, add the data to your data structure, and it's that simple. Plus, you can re-use the data structure with HTML::Template and PDF::Template, meaning you now have 3 formats from one data structure. AND, if there's any bugs in the Excel generation, assuming you've used E::T right, it's my fault, not yours. :-)


My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

In reply to Re: problem using perl module Spreadsheet::WriteExcel cannot get data into rows when using for loop on a list to populate rows by dragonchild
in thread problem using perl module Spreadsheet::WriteExcel cannot get data into rows when using for loop on a list to populate rows by adamlee14

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.