use strict; use warnings; use Spreadsheet::WriteExcel; use DBI; my $file = "/path/to/file/"; my $xWB = Spreadsheet::WriteExcel->new($file); my $xWS5 = $xWB->add_worksheet('Summary'); my $format = $xWB->add_format(); $format->set_bold(); #DBI stuff here.. my $row_count = $sth->rows; my $multiply = $xWS5->store_formula("=E2*F2"); # write worksheet my $rowz = 0; my $colz = 0; $xWS5->write($rowz,$colz++, $_) for @{$sth->{NAME}}; while (my $ar = $sth->fetchrow_arrayref) { ++$rowz; $colz = 0; $xWS5->write($rowz, $colz++, $_) for @$ar; for my $line (0..$row_count) { #this arguments are row, column, formula, format, first cell, second cell $xWS5->repeat_formula($line, 6, $multiply, $format, "E2", 'E'.($line + 1), "F2", 'F'.($line + 1)); } }