Paul Kraus wrote: > I am dumping rows of an array into an excel file. I would like those > rows to be sorted. If I wanted them to be sorted by the first elements > how would I do it? > > Code > ---- > #!/usr/bin/perl -w > use strict; > use Spreadsheet::WriteExcel; > open IN, ($ARGV[0]); > my @AoA; > while (<IN>){ > chomp; > push (@AoA,[(split /\|/,$_)]); > } > > my $workbook = Spreadsheet::WriteExcel->new("perl.xls"); > my $endo=$workbook->addworksheet('ENDO00'); > my $baue=$workbook->addworksheet('BAUE00'); > my $fore=$workbook->addworksheet('FORE00'); > my $fill=$workbook->addworksheet('FILL00'); > my $hosm=$workbook->addworksheet('HOSM00'); > my $ipos=$workbook->addworksheet('IPOS00'); > my $ohio=$workbook->addworksheet('OHIO00'); > my $seat=$workbook->addworksheet('SEAT00'); > > for my $i (0 .. $#AoA){ > for my $j (0 .. $#{$AoA[$i]}) { > $AoA[$i][$j]=~s/\s+$//g; > $AoA[$i][$j]=~s/^\s+//g; > } > } > > my @count = (0,0,0,0,0,0,0,0); > > foreach (@AoA){ > if (@$_[3] eq 'ENDO00'){ > $endo->write_row($count[0],0,\@$_); > $count[0]++;} > if (@$_[3] eq 'BAUE00'){ > $baue->write_row($count[1],0,\@$_); > $count[1]++;} > if (@$_[3] eq 'FORE00'){ > $fore->write_row($count[2],0,\@$_); > $count[2]++;} > if (@$_[3] eq 'FILL00'){ > $fill->write_row($count[3],0,\@$_); > $count[3]++;} > if (@$_[3] eq 'HOSM00'){ > $hosm->write_row($count[4],0,\@$_); > $count[4]++;} > if (@$_[3] eq 'IPOS00'){ > $ipos->write_row($count[5],0,\@$_); > $count[5]++;} > if (@$_[3] eq 'OHIO00'){ > $ohio->write_row($count[6],0,\@$_); > $count[6]++;} > if (@$_[3] eq 'SEAT00'){ > $seat->write_row($count[7],0,\@$_); > $count[7]++;} > } > > > Output (excel file) - I would like each sheet sorted by year. > ------------------- > Year item description vend > sale qty prod code > 1999 10011 Knee Platform Assy KT Univ Mark V SEAT00 266 > 4 ENDO > 2000 10011 Knee Platform Assy KT Univ Mark V SEAT00 71 > 1 ENDO > 2001 10011 Knee Platform Assy KT Univ Mark V SEAT00 216 > 3 ENDO > 2002 10011 Knee Platform Assy KT Univ Mark V SEAT00 72 > 1 ENDO > 2000 10073 Knee Platform Assembly for Mark V SEAT00 82 > 2 ENDO > 2001 10073 Knee Platform Assembly for Mark V SEAT00 87 > 2 ENDO > > > In fact if I could sort it by year and then decending order within > year for sales that would be perfect or better yet sorted and then > each year having a total line and then a space before the next year. > Thanks!!
Could I see what the data looks like coming in? It should not be that hard to do, but as they say a picture is worth a 1000 words. So a small file would be worth plenty. Wags ;) ********************************************************** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. **************************************************************** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]