WriteExcel->sheets() fails to get the worksheets

A

Anand

I am trying to read an excel file usign the writeexcel. Following is
the code-snippet:
my $workbook = Spreadsheet::WriteExcel->new('Temp.xls');

print "Cannot create Temp.xls: $!\n" if (not defined $workbook);

foreach $worksheet ($workbook->sheets()) {
print "Worksheet Name is: ".$worksheet->get_name()."\n";
}

The file Temp.xls is already existing in the directory. I want to
further modify the worksheets. However, the sheets() method itself is
not working.
What might be the reason? I'm using perl 5.8

Thanks,
Anand.
 
B

Ben Bullock

To modify an existing spreadsheet file, your choice is to create a new,
empty spreadsheet with Spreadsheet::WriteExcel, read the existing
spreadsheet with Spreadsheet::parseExcel, and copy the information in
the existing spreadsheet to the new one, or search CPAN for a module
that can update an existing spreadsheet. I believe there used to be one,
but I have never used it and cannot find it.

The obvious solution is to use Win32::OLE to do everything. I'd only use
the Perl Excel reading / writing modules if I had to do something with an
Excel spreadsheet on Unix.
 
A

Anand

Anand said:
I am trying to read an excel file usign the writeexcel. Following is
the code-snippet:
my $workbook = Spreadsheet::WriteExcel->new('Temp.xls');
print "Cannot create Temp.xls: $!\n" if (not defined $workbook);
foreach $worksheet ($workbook->sheets()) {
print "Worksheet Name is: ".$worksheet->get_name()."\n";
}
The file Temp.xls is already existing in the directory. I want to
further modify the worksheets. However, the sheets() method itself is
not working.
What might be the reason? I'm using perl 5.8

Have you read the documentation for Spreadsheet::WriteExcel?

From 'perldoc Spreadsheet::WriteExcel':

"This module cannot be used to write to an existing Excel file."

To modify an existing spreadsheet file, your choice is to create a new,
empty spreadsheet with Spreadsheet::WriteExcel, read the existing
spreadsheet with Spreadsheet::parseExcel, and copy the information in
the existing spreadsheet to the new one, or search CPAN for a module
that can update an existing spreadsheet. I believe there used to be
one, but I have never used it and cannot find it.

--
Jim Gibson


----------------------------------------------------------
color]

Thanks Jim.

I could successfully use WriteExcel to create a workbook. I created
three worksheets. However, I'm having issues when I switch between
sheets.
If I switch between the sheets, the output file vanishes and gets
replaced by an empty file.

$oSheet1 = $oWorkbook->sheets(0);

..... Write some data on Sheet(0).....

$oSheet2 = $oWorkbook->sheets(1);

..... Write some data on sheet(1);

After theses statements, my output file is of zero size with no data
in it.
If I use only one sheet of the two, it works fine but updates only one
sheet.

thanks,
Anand.
 

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

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top