Dear Monks,

I'm trying to encapsulate Spreadsheet::WiteExcel functionality in a larger script. It may be a silly mistake but in the moment I cannot succeed writing some cells...

I get an empty Excel worksheet. The module itself works. Writing in the new() constructor $worksheet->write( 1, 0, 42 ) yields the expected result. Using my writerow() method though seems useless.

Can you please point me to my misunderstanding?

Many thanks, Axel.


#!perl -w use strict; my $tmpl = ExcelWriter->new(); my @row = ( 1, 2, 3 ); $tmpl->writerow( \@row ); BEGIN { package ExcelWriter; use Spreadsheet::WriteExcel; my $tmpfile = sprintf( "/tmp/%d.%d.xls", time % 1000, int rand(1000) ); sub new { my $class = shift; my $workbook = Spreadsheet::WriteExcel->new($tmpfile) or die $!; my $worksheet = $workbook->addworksheet('Data'); bless \$worksheet, $class; } sub writerow { my ( $self, $row ) = @_; my $worksheet = $$self; for ( 0 .. @$row - 1 ) { $worksheet->write( 0, $_, $row->[$_] ); } } }
To check you need to open the resulting tmpfile. I'm testing with MacPerl5.6.1 btw.

In reply to writing with WriteExcel in OO style by axelrose

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.