Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^4: Trying to modify multisheets using Spreadsheet::ParseExcel::SaveParser

by ravi45722 (Pilgrim)
on Aug 14, 2015 at 07:22 UTC ( [id://1138532]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Trying to modify multisheets using Spreadsheet::ParseExcel::SaveParser
in thread Trying to modify multisheets using Spreadsheet::ParseExcel::SaveParser

#!usr/bin/perl use DBI; use Spreadsheet::ParseExcel; use Spreadsheet::ParseExcel::SaveParser; $month=$ARGV[0]; $month or $month=`date --date='1 day ago' +%B`; chomp $month; print "Month:$month\n"; my $dbh = DBI->connect("DBI:mysql:database=MIS_Reports;host=172.16.15. +104;mysql_socket=/opt/lampstack-5.5.27-0/mysql/tmp/mysql.sock","root" +,"", {'RaiseError' => 1}); #--------------------------------------------------------------------- +------------------------------------# # Open an existing file with SaveParser my $parser = Spreadsheet::ParseExcel::SaveParser->new(); my $template = $parser->Parse('B_MUM_dashboard_month_latency_corrected +_FDB.XLS'); @tables=("MIS_Overall","MIS_P2P","MIS_P2A","MIS_A2P"); $sheet_no=0; foreach $table (@tables) { chomp $table; my $sth = $dbh->prepare("SELECT * from $table where monthname(Date +)='$month'" ); $sth->execute() or die $DBI::errstr; # Get the first worksheet. my $sheet = $template->worksheet($sheet_no); my $row = 2; my $col = 1; while (my @row = $sth->fetchrow_array()) { $col=1; foreach my $value (@row) { $sheet->AddCell( $row, $col, $value ); ++$col; } $row++; } $sheet_no++; } $template->SaveAs('B_MUM_dashboard_month_latency_corrected_FDB_12-08-2 +015.XLS');

Error: Can't call method "worksheet" on an undefined value at parse_excel_multisheet.pl line 33

  • Comment on Re^4: Trying to modify multisheets using Spreadsheet::ParseExcel::SaveParser
  • Download Code

Replies are listed 'Best First'.
Re^5: Trying to modify multisheets using Spreadsheet::ParseExcel::SaveParser
by Corion (Patriarch) on Aug 14, 2015 at 07:56 UTC

    This means that $template was not initialized properly. Check the return value of

    my $template = $parser->Parse('B_MUM_dashboard_month_latency_corrected +_FDB.XLS');

    like this

    my $filename = 'B_MUM_dashboard_month_latency_corrected_FDB.XLS'; my $template = $parser->Parse($filename) or die "Couldn't read '$filename': " . $parser->error;

    That way, you find out why your template was not initialized properly.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-19 01:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found