CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [Tejas] How to append or prepend a string to a variable : Edit Log



Zhris
Enthusiast

Nov 19, 2014, 12:31 AM


Views: 13118
Re: [Tejas] How to append or prepend a string to a variable

Hi,

The key issue with both your examples is that you are assigning a variable with a string, but then later using it like an object by attempting to call a method on it, resulting in "Can't call method "sheets" without a package or object reference" error:


Code
my $workbook = $Orgs[$col]; # assigns workbook with string i.e. US. 
...
foreach my $worksheet ($workbook->sheets()) # attempts to call method sheets on workbook string.


The below is completely untested, but is what I think you should be doing instead:


Code
my @orgs = ('US','GB','DE','ES','IT','FR','GB','MX','BR','AU'); # note duplicate gb.  

for my $org ( @orgs )
{
my $workbook = Excel::Writer::XLSX->new( "${org}_GL_SL.xlsx");
$workbook->add_worksheet( 'GL_Sheet' );
$workbook->add_worksheet( 'SL_Sheet' );

print "${org}_workbook";

for my $worksheet ( $workbook->sheets( ) )
{
$worksheet->set_column( 'A:Q', 20 ); # Column E width set to 20
}
}


You had alot of duplicate workbook instantiations at the top, 1 for each org, this can be reduced by handling in the org for loop instead. the variable $workbook is then handly an org specific excel writer object.

Regards,

Chris


(This post was edited by Zhris on Nov 19, 2014, 12:39 AM)


Edit Log:
Post edited by Zhris (Enthusiast) on Nov 19, 2014, 12:32 AM
Post edited by Zhris (Enthusiast) on Nov 19, 2014, 12:35 AM
Post edited by Zhris (Enthusiast) on Nov 19, 2014, 12:36 AM
Post edited by Zhris (Enthusiast) on Nov 19, 2014, 12:38 AM
Post edited by Zhris (Enthusiast) on Nov 19, 2014, 12:39 AM
Post edited by Zhris (Enthusiast) on Nov 19, 2014, 12:39 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives