skywalker has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I am using the fantastic spreadsheet::WriteExcel by John McNamara, however I cant find any way of creating a border over a range of cells with out creating the range individualy. ie, is there a way to write
$format = $workbook->add_format(border => 1); $worksheet->write('A1:D3',$format);
rather than

$format = $workbook->add_format(border => 1); $worksheet->write('A1','undef',$format); $worksheet->write('B1','undef',$format); $worksheet->write('C1','undef',$format); ect

Thanks

skywalker

Replies are listed 'Best First'.
Re: spreadsheet write excel border creation
by kennethk (Abbot) on Mar 30, 2009 at 16:20 UTC

    I'm personally not terribly familiar with the module in question, but based upon the documentation, there doesn't appear to be range support for the write method. However, you could implement the functionality you desire using nested loops. You could use row-column notation like:

    $format = $workbook->add_format(border => 1); for my $row (0 .. 2) { for my $column (0 .. 3) { $worksheet->write($row, $column,'undef',$format); } }

    or using A1 notation:

    $format = $workbook->add_format(border => 1); for my $row (1 .. 3) { for my $column ('A' .. 'D') { $worksheet->write($column.$row,'undef',$format); } }

    Note that Perl is smart enough to deal with alphabetic indices in a limited fashion using Auto increment and Auto decrement and the Range Operators.

    As a side note, if you wish to link to a module on CPAN on PerlMonks, use the notation [mod://spreadsheet::WriteExcel]. See more information in What shortcuts can I use for linking to other information?.

      Thanks for that,

      I thought I might have to go around this the long way round, other than this one very minor issue Spreadsheet::WriteExcel truly is a great peice of kit.

      Skywalker

      also thanks for pointing out the correct way to link to a module