Dynamic Ref names

W

Warrick FitzGerald

Hi All,

I'm trying to dynamically create worksheets using Spreadsheet::WriteExcel.

I'm looking through a log file and would like to create a worksheet for
each date.

In all example I can find you simply do:
$mySheet = $workbook->addworksheet("somename");

then to add data to that you simply do:
$mySheet->write(....);

That works great until I try to dynamically create $mySheet.

--------------
This is what I tried.

$date = $Fields[0]; <--- Get the date from the Logfile

${$date} = $workbook->addworksheet($date); <-- This created the workbook
for each date. date is of course formatted to be excel friendly name.

My problem come when trying to call the write method on my dynamic name.

${$date}->write(...) does not work ?
%{$date}->write(...) does not work ?

I have tried everything I can think of. Can someone please tel me how I
can call the write method on a dynamically named worksheet?

Thanks
Warrick FitzGerald
 
B

Ben Morrow

Warrick FitzGerald said:
I'm trying to dynamically create worksheets using Spreadsheet::WriteExcel.

I'm looking through a log file and would like to create a worksheet for
each date.

In all example I can find you simply do:
$mySheet = $workbook->addworksheet("somename");

then to add data to that you simply do:
$mySheet->write(....);

That works great until I try to dynamically create $mySheet.

--------------
This is what I tried.

$date = $Fields[0]; <--- Get the date from the Logfile

${$date} = $workbook->addworksheet($date); <-- This created the workbook
for each date. date is of course formatted to be excel friendly name.

Are you using strictures? Why not?

You don't need to name the variable after the sheet name:

$mySheet = $workbook->addworksheet($date);

will work perfectly well. If you're trying to keep hold of several
sheets at once, one for each date, you should use a hash, not the symbol
table:

my %sheets;

$sheets{$date} = $workbook->addworksheet($date);

Ben
 
J

John McNamara

Warrick said:
This is what I tried.

$date = $Fields[0]; <--- Get the date from the Logfile

${$date} = $workbook->addworksheet($date); <-- This created the workbook
for each date. date is of course formatted to be excel friendly name.

My problem come when trying to call the write method on my dynamic name.

Here is a short example:

#!/usr/bin/perl -w

use strict;
use Spreadsheet::WriteExcel;

my $workbook = Spreadsheet::WriteExcel->new("dates.xls");

my %worksheets;

my $date = '2004-02-18';


$worksheets{$date} = $workbook->addworksheet($date);

$worksheets{$date}->write("A1", "Hello world");

__END__


John.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top