here is my code.. #!/usr/local/bin/perl
use strict;
use Env;
use Spreadsheet::WriteExcel();
use Spreadsheet::ParseExcel;
use OLE::Storage_Lite;
# Globals
$oBook =  Spreadsheet::ParseExcel::Workbook->Parse("/home/d219103/rdnaudit.xls");
$rowCounter = 1;
@devicesPerVariant = ();
@model = ();
@processor = ();
@memory = ();
@softwareVersion = ();
@listOfHardwareTypes = &generateListOfHardwareTypes();
foreach $hardwareTypes (@listOfHardwareTypes) {
print "Hardware type is $hardwareTypes\n";
@hardwareMatchEntries = &getAllHardwareTypes($hardwareTypes);
&prepareAndSortModelDataForSpreadsheet(@hardwareMatchEntries);
print "\nDevices = $devicePerModel\n";
print "Unique Device counts = @devicesPerVariant\n";
print "Unique Device models = @model\n";
print "Unique Device processors = @processor\n";
print "Unique Device memory = @memory\n";
print "Unique Device software = @softwareVersion\n";
# Call excel spreadsheet adding here
&populateExcelRows();
# Reset these variable
@devicesPerVariant = "";
@model = "";
@processor = "";
@memory = "";
@softwareVersion = "";
}
sub generateListOfHardwareTypes
{
my($i,$oWkS,$oWkC);
my(@uniqueList);
foreach my $oWkS (@{$oBook->{Worksheet}}) {
$i = 1;
$oWkC = $oWkS->{Cells}[$i][1];
$CellValue = $oWkC->Value;
while($CellValue) {
# Check if cellvalue is unique
if (&searchString($CellValue, \@uniqueList)) {
push @uniqueList, $CellValue;
}
$i++;
# Get next CellValue
$oWkC = $oWkS->{Cells}[$i][1];
if (exists $oWkS->{Cells}[$i][1]) {
$CellValue = $oWkC->Value;
} else {
$CellValue = 0; <code>}

}
}
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;
}
}
} <code>#print "@HWList\n";

return @HWList;
} <code>sub prepareAndSortModelDataForSpreadsheet {

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();

In reply to Re^2: problem using perl module Spreadsheet::WriteExcel cannot get data into rows when using for loop on a list to populate rows by adamlee14
in thread problem using perl module Spreadsheet::WriteExcel cannot get data into rows when using for loop on a list to populate rows by adamlee14

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.