Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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]
[Discipulus]: good morning nuns and monks!

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2018-06-25 07:08 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.