Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.