in reply to Re: problem using perl module Spreadsheet::WriteExcel cannot get data into rows when using for loop on a list to populate rows
in thread problem using perl module Spreadsheet::WriteExcel cannot get data into rows when using for loop on a list to populate rows
} } return @uniqueList; } sub searchString { $value = $_[0]; $theList_ptr = $_[1]; my @theList = @$theList_ptr; #print "Value is $value, List is @theList\n"; if (@theList) { foreach $entry (@theList) { chomp(@theList); if ($entry eq $value ) { return 0; } } } return 1; } sub getAllHardwareTypes { my($i,$oWkS,$aWkC,$bWkC,$cWkC,$dWkC,$eWkC); my(@HWList); $compareValue = $_[0]; foreach my $oWkS (@{$oBook->{Worksheet}}) { $i = 1; $aWkC = $oWkS->{Cells}[$i][0]; $bWkC = $oWkS->{Cells}[$i][1]; $cWkC = $oWkS->{Cells}[$i][2]; $dWkC = $oWkS->{Cells}[$i][3]; $eWkC = $oWkS->{Cells}[$i][4]; $AcolValue = $aWkC->Value; $BcolValue = $bWkC->Value; $CcolValue = $cWkC->Value; $DcolValue = $dWkC->Value; $EcolValue = $eWkC->Value; while($BcolValue) { # Check if B Column value is a match if ($BcolValue eq $compareValue) { push @HWList, "$AcolValue,$BcolValue,$CcolValue,$DcolValue,$EcolValue"; #print "$AcolValue,$BcolValue,$CcolValue,$DcolValue,$EcolValue\n"; } $i++; #Get next Bcolumn Value $aWkC = $oWkS->{Cells}[$i][0]; $bWkC = $oWkS->{Cells}[$i][1]; $cWkC = $oWkS->{Cells}[$i][2]; $dWkC = $oWkS->{Cells}[$i][3]; $eWkC = $oWkS->{Cells}[$i][4]; if (exists $oWkS->{Cells}[$i][0]) { $AcolValue = $aWkC->Value; } if (exists $oWkS->{Cells}[$i][1]) { $BcolValue = $bWkC->Value; } else { $BcolValue = 0; } if (exists $oWkS->{Cells}[$i][2]) { $CcolValue = $cWkC->Value; } if (exists $oWkS->{Cells}[$i][3]) { $DcolValue = $dWkC->Value; } if (exists $oWkS->{Cells}[$i][4]) { $EcolValue = $eWkC->Value; } }$CellValue = 0; <code>}
return @HWList;} <code>#print "@HWList\n";
my @inputArray = @_; # populate these variables $devicePerModel = $#inputArray; $devicePerModel++; my @array = (); my @out = (); my $line = (); my $entry = (); foreach $line (@inputArray) { if ($line =~ m/^.*?,(.*)/) { #print "$1\n"; push @array, $1; } } # Sort unique entries from data undef %saw; @saw{@array} = (); @out = sort keys %saw; foreach $entry (@out) { # These are unique entries $count = 0; foreach $line (@array) { if ($entry eq $line) { $count++; } } push @devicesPerVariant, $count; if ($entry =~ m/(.*?),(.*?),(.*?),(.*)/) { push @model, $1; push @processor, $3; push @memory, $4; push @softwareVersion, $2; } } } sub populateExcelRows { 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'); $worksheet->write(0,2, 'Devices Per Variant'); $worksheet->write(0,3, 'Model Variant Processor'); $worksheet->write(0,4 , 'Device Memory'); $worksheet->write(0,5 , 'Device Software'); #Loop through Global Array called Models to determine the number of rows to place data for ($j = 1; $j <= $#model; $j++) { print "row is $rowCounter, $model[$j], $devicesPerVariant[$j], $processor[$j], $memory[$j], <code>$softwareVersion[$j]\n"; $worksheet->write($rowCounter,0, $model[$j]); if ($j == 0) { $worksheet->write($rowCounter,1, $devicePerModel); } # Are you sure that all of your arrays have the same length? $worksheet->write($rowCounter,2, $devicesPerVariant[$j]); $worksheet->write($rowCounter,3, $processor[$j]); $worksheet->write($rowCounter,4, $memory[$j]); $worksheet->write($rowCounter,5, $softwareVersion[$j]); $rowCounter++; } $workbook->close();} <code>sub prepareAndSortModelDataForSpreadsheet {
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: problem using perl module Spreadsheet::WriteExcel cannot get data into rows when using for loop on a list to populate rows
by GrandFather (Saint) on Sep 14, 2005 at 06:10 UTC | |
by adamlee14 (Initiate) on Sep 14, 2005 at 07:04 UTC | |
by GrandFather (Saint) on Sep 14, 2005 at 07:55 UTC | |
by adamlee14 (Initiate) on Sep 15, 2005 at 03:50 UTC |