Nice. ++

Here is another way to do it using the new Spreadsheet::WriteExcelXML module.

It doesn't support all of the features of Spreadsheet::WriteExcel but they will be added in time.

#!/usr/bin/perl -w use strict; use Spreadsheet::WriteExcelXML; my $workbook = Spreadsheet::WriteExcelXML->new("demo.xml"); my $worksheet = $workbook->add_worksheet(); my $bold = $workbook->add_format(bold => 1); my @test_array1 = ( [2, 3, 5], [7, 11, 13], [17, 19, 23], ); my @test_array2 = ( ['', 'Height', 'Siblings'], ['Joe', 77, 1 ], ['Frank', 70, 4 ], ); $worksheet->write_col('A1', \@test_array1); $worksheet->write('A7', $test_array2[0], $bold); $worksheet->write('A8', $test_array2[1] ); $worksheet->write('A9', $test_array2[2] );

The output which can be read by Excel 2002 and 2003 looks like this:

<?xml version="1.0"?> <?mso-application progid="Excel.Sheet"?> <Workbook xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"> <Styles> <Style ss:ID="s21"> <Font ss:Bold="1"/> </Style> </Styles> <Worksheet ss:Name="Sheet1"> <Table ss:ExpandedColumnCount="3" ss:ExpandedRowCount="9"> <Row> <Cell> <Data ss:Type="Number">2</Data> </Cell> <Cell> <Data ss:Type="Number">3</Data> </Cell> <Cell> <Data ss:Type="Number">5</Data> </Cell> </Row> <Row> <Cell ss:Index="1"> <Data ss:Type="Number">7</Data> </Cell> <Cell> <Data ss:Type="Number">11</Data> </Cell> <Cell> <Data ss:Type="Number">13</Data> </Cell> </Row> <Row> <Cell ss:Index="1"> <Data ss:Type="Number">17</Data> </Cell> <Cell> <Data ss:Type="Number">19</Data> </Cell> <Cell> <Data ss:Type="Number">23</Data> </Cell> </Row> <Row ss:Index="7"> <Cell ss:Index="1" ss:StyleID="s21"/> <Cell ss:StyleID="s21"> <Data ss:Type="String">Height</Data> </Cell> <Cell ss:StyleID="s21"> <Data ss:Type="String">Siblings</Data> </Cell> </Row> <Row> <Cell ss:Index="1"> <Data ss:Type="String">Joe</Data> </Cell> <Cell> <Data ss:Type="Number">77</Data> </Cell> <Cell> <Data ss:Type="Number">1</Data> </Cell> </Row> <Row> <Cell ss:Index="1"> <Data ss:Type="String">Frank</Data> </Cell> <Cell> <Data ss:Type="Number">70</Data> </Cell> <Cell> <Data ss:Type="Number">4</Data> </Cell> </Row> </Table> </Worksheet> </Workbook>

--
John.


In reply to Re: Two-dimensional array to "Excel" format by jmcnamara
in thread Two-dimensional array to "Excel" format by delirium

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.