If you are using SpreadSheet::WriteExcel you can specify the name of the worksheet as the method add_worksheet's first param. This is what the doc says:
$worksheet1 = $workbook->add_worksheet(); # Sheet1
$worksheet2 = $workbook->add_worksheet('Foglio2'); # Foglio2
$worksheet3 = $workbook->add_worksheet('Data'); # Data
$worksheet4 = $workbook->add_worksheet(); # Sheet4
So what you'd want to do is probably something like this:
while (my $res = $dbh->fetchrow_hashref) {
my $worksheet = $workbook->add_worksheet($res->{'customerName'});
# do stuff with that sheet
}
Update:
Since you're only using Spreadsheet::ParseExcel here's another idea. There's no setter method for the name, so let's take a deeper look to find a workaround.
The code of Spreadsheet::ParseExcel::Worksheet shows us how the name of a workbook-object is stored:
###############################################################################
#
# get_name()
#
# Returns the name of the worksheet.
#
sub get_name {
my $self = shift;
return $self->{Name};
}
You can just access the key Name directly via the worksheet-object.
$worksheet->{'Name'} = $res->{'customerName'};
Disclaimer: You should never meddle with internal values of objects, especially if you do not have control over their source. The internal structure may change in a future release, thus breaking your code!