I am using Spreadsheet::WriteExcel to create a spreadsheet with two columns in it. It works. I have one final little problem.

here's the code

open FILE,'>','feckyou.txt' or die $!; my $workbook = Spreadsheet::WriteExcel->new('newproduct.xls'); my $worksheet = $workbook->add_worksheet(); for my $row (1..$row_max){ my $valA = $sheet->{Cells}[$row][0]->{Val}; # does this value exist in Col D if (exists $colD{$valA}) { my $valB = $sheet->{Cells}[$row][1]->{Val}; my $xlrow = $row+1; print FILE "price change [A$xlrow]=[D$colD{$valA}] Value=$valB\n"; } #output new products to text file elsif (!exists $colD{$valA}) { # open FILE2, '>','newproducts.txt' or die $!; my $valB = $sheet->{Cells}[$row][1]->{Val}; # print FILE2 "New Product: = $valA Price = $valB\n"; # close FILE2; $worksheet->write ($row+1, 0, "$valA"); $worksheet->write ($row+1, 1, "$valB"); } }

for some reason it puts the values in the new worksheet on the row that it finds them on in the original. So the spreadsheet is 3700 lines long with row after row of blank space. I need it to write to the new spreadsheet without writing the blank cells or matching the row from the original. I hope I described it well. example: If it finds a new product (with the elsif) on row 27 in the original it copies it to row 27 in the new one im creating with the script. If it doesn't find another new product code until row 3200, it will write that to line 3200 on the new one, so I'll have 3173 empty rows. Ive messed with the syntax and am not getting it, i'm sure its something stupid, but I need it to write the values in order, row 1, row 2, etc regardless of where its found in the original.

does that make sense?

thanks once again

<

In reply to the final thorn in your toe by trickyq

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.