#!usr/bin/perl #use strict; #use warnings; use DBI; use Spreadsheet::ParseExcel; use Spreadsheet::ParseExcel::SaveParser; use Spreadsheet::Read; 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}); #Selecting the data to fetch @tables=("MIS_Overall","MIS_P2P","MIS_P2A","MIS_A2P"); #my $sth = $dbh->prepare("SELECT * from MIS_P2P"); #my $dates=$dbh->prepare("select Date from MIS_Overall where monthname(Date)='August'"); #$dates->execute() or die $DBI::errstr; # Open an existing file with SaveParser my $parser = Spreadsheet::ParseExcel::SaveParser->new(); my $template = $parser->Parse('B_MUM_dashboard_month_latency_corrected_FDB.XLS'); #*********************************************************************************************************# foreach my $MIS_SHEET (@tables) { # Get the first worksheet. my $sheet = $template->worksheet($MIS_SHEET); my $row_in = 2; my $col_in = 0; my $sth = $dbh->prepare("SELECT * from $MIS_SHEET"); $sth->execute() or die $DBI::errstr; while (my @row = $sth->fetchrow_array()) { ++$row; foreach my $value (@row) { $sheet->AddCell( $row, $col, $value ); ++$col; } } } $template->SaveAs('B_MUM_dashboard_month_latency_corrected_FDB_2015_08_01.XLS');