# Open an existing file with SaveParser my $parser = Spreadsheet::ParseExcel::SaveParser->new(); my $template = $parser->Parse('perl.xls'); my @s; $s[$_] = $template->worksheet( "cpzea0".$_."a0001" ) for 1..8; ########################################################################################################################################################### #####This will retrieve the last row where value was written form the first worksheet so that we can continue writing from the same place################## my $cell = $s[1]->get_cell(1000,1); $lrow= $cell->value; print $lrow; ########################################################################################################################################################## my $workbook= $template->SaveAs('newfile.xls'); for ($i=0;$i<=7;$i++) { $s[$i+1] = $workbook->sheets($i) ; } ########################################################################################################################################################### ####All the Formats will be described within this space##################################################################################################### my $text_format = $workbook->add_format( bold => 1, size => 10, font =>'arial', bg_color =>'green', align =>'center', border =>'1' ); my $text_format1 = $workbook->add_format( size => 10.5, font =>'consolas', align =>'center', ); my $text_format2 = $workbook->add_format( size => 10.5, font =>'consolas', align =>'center', bg_color =>'dark blue', border =>'1' ); my $text_format3=$workbook->add_format( size => 10.5, font =>'consolas', align =>'center', border =>'1' , color =>'red', bold =>'1', ); ############################################################################################################################################################ $row=$lrow + 3; $col=1; $start=$row; for($i=1;$i<=8;$i++) { $f=0; for ($c=$col+1;$c<=8;$c++) { $s[$i]->write($start,$c,$header[$f++],$text_format); } } my $col = 1; for ($i=1;$i<=8;$i++) { for ($r=0;$r<=24;$r++) { $row++; for ($c=0;$c<=4;$c++) { $col++; $s[$i]->write($row,$col,$arrays[$i][$r][$c],$text_format1); } $col=1; } $row=$lrow + 3; } #This part will create Formulae for current day my $c=7 ; for ($i=1;$i<=8;$i++) { for ($r=$lrow + 4;$r<=$lrow + 28;$r++) { $c=$r + 1; $s[$i]->write($r,7,"=F$c/G$c",$text_format2); $s[$i]->write($r,8,"=F$c/SUM(C$c:D$c)",$text_format2); } } ######################################################################################################################################################### #This part is for writting the last line of the data which calculates the sum of each parameter for a given day########################################### my $g =2; $row=$lrow + 28; $val=$lrow + 5; for ($i=1;$i<=8;$i++) { $s[$i]->write($row,$g++,"Total",$text_format3); $s[$i]>write($row,$g++,"=SUM(D$val:D$row)",$text_format3); $s[$i]->write($row,$g++,"=SUM(E$val:E$row)",$text_format3); $s[$i]->write($row,$g++,"=SUM(F$val:F$row)",$text_format3); $s[$i]->write($row,$g++,"=SUM(G$val:G$row)",$text_format3); $g=2; } ########################################################################################################################################################### $s[1]->write(1000,1,$lrow + 30); $workbook->close();