Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Not able to create worksheets inside a subroutine

by hdb (Monsignor)
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();

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1056232]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2017-08-22 02:32 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (326 votes). Check out past polls.