#!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-2015.XLS');