Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Not able to create worksheets inside a subroutine

by hdb (Parson)
on Sep 29, 2013 at 15:50 UTC ( #1056232=note: print w/ replies, xml ) Need Help??


in reply to Not able to create worksheets inside a subroutine

One typo in your code might cause the problem:

$workbook = Spreadsheet::WriteExcel>new('FAISTATS_'."$Month".'.xls');
should be
$workbook = Spreadsheet::WriteExcel->new('FAISTATS_'."$Month".'.xls');

When I corrected this and ran it under use strict; (a few declarations are needed...), it created a file with the desired sheets.

use warnings; use strict; use Spreadsheet::WriteExcel; use Spreadsheet::ParseExcel; use Spreadsheet::ParseExcel::SaveParser; my $Month = 9; my @s; sub create_excel { my $workbook = Spreadsheet::WriteExcel->new('FAISTATS_'."$Month".'.x +ls'); for ( my$i=1;$i<=8;$i++) { $s[$i] = $workbook->add_worksheet( "rpzea0".$i."a001" ) ; } } create_excel();


Comment on Re: Not able to create worksheets inside a subroutine
Select or Download Code
Re^2: Not able to create worksheets inside a subroutine
by devbond (Novice) on Sep 29, 2013 at 16:00 UTC
    Thanks...i found out what the problem is...i was not declaring wrokbook as type my(local).Can you try running you code after removing my it woudnt work..i dont understand why

      No, removing my is not the way to go at all. Always use strict;, clear away all errors and then see what happens.

        I cant declare workbook as my as i need to use it in other subs too

      Spreadsheet::WriteExcel tries to close your workbook automatically but sometimes has problems "If the new(), add_worksheet() or add_format() methods are called in subroutines." You can read the section on the close() method for more detail on limitations of automatic closing.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1056232]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (15)
As of 2014-09-01 15:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (15 votes), past polls