in reply to Spreadsheet::WriteExcel Loop problem
You should trim your code down to a minimum (you are improving) and make it stand alone so that we can reproduce your problem.
if ($j == 0) is always false because your loop starts with $j = 1.
If I edit your code to this:
use warnings; use strict; use Spreadsheet::WriteExcel; my @model = qw(x a b c d); my @devicesPerVariant = qw(x 2 1 3 1); my $rowCounter = 1; my $devicePerModel = 2; my $workbook = Spreadsheet::WriteExcel->new("test.xls"); my $worksheet = $workbook->add_worksheet(); my $j = 1; #Declare Headings for row 0 and the 6 Columns $worksheet->write(0,0 , 'Equipment Model'); $worksheet->write(0,1, 'Devices Per Model'); #Loop through Global Array called Models to determine the number of ro +ws to place data for (my $j = 1; $j <= $#model; $j++) { print "row is $rowCounter, $model[$j], $devicesPerVariant[$j]\n"; $worksheet->write($rowCounter,0, $model[$j]); if ($j == 0) { $worksheet->write($rowCounter,1, $devicePerModel); } $worksheet->write($rowCounter,2, $devicesPerVariant[$j]); $rowCounter++; } $workbook->close();
I get a spreedsheet containing:
Equipment Model Devices Per Model a 2 b 1 c 3 d 1
which is what I would expect to get.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Spreadsheet::WriteExcel Loop problem
by adamlee14 (Initiate) on Sep 16, 2005 at 05:21 UTC | |
by GrandFather (Saint) on Sep 16, 2005 at 05:40 UTC |