# query prepared and executed here... my $xWB = Spreadsheet::WriteExcel->new('spreadsheet.xls'); my $xWS2 = $xWB->add_worksheet('Report'); my $big_num_format = $xWB->add_format(); $big_num_format->set_num_format('##,###,##0'); my $row = 0; my $col = 0; $xWS2->write($row,$col++, $_) for @{$sth2->{NAME}}; while (my $array_ref = $sth2->fetchrow_arrayref) { ++$row; $col = 0; $xWS2->write($row, $col++, $_) for @$array_ref; if ($col == 1) { $xWS2->write_number( 0, 1, $_, $big_num_format) for @$array_ref; $xWS2->write_number( 1, 1, $_, $big_num_format) for @$array_ref; } }