trickyq has asked for the wisdom of the Perl Monks concerning the following question:
here's the whole script so you can see what it needs to accomplish.
I need it to write that data from the ifelse portion of the script to the new spreadsheet without skipping rows. I was given a few ideas, none of which were ideal. because I didn't enter the whole script, so you guys couldn't see how it starts and where the data comes from. So here it is.#!/usr/bin/perl use strict; use Spreadsheet::XLSX; use SpreadSheet::WriteExcel; my $excel = Spreadsheet::XLSX -> new ('build.xlsx'); my $sheet = $excel->Worksheet('Sheet1'); my ($row_min,$row_max) = $sheet->row_range(); # scan col D and store values my %colD=(); for my $row ($row_min..$row_max){ my $valD = $sheet->{Cells}[$row][3]->{Val}; $colD{$valD} = $row+1; # excel row number } # scan col A starting at row 2 open FILE,'>','feckyou.txt' or die $!; my $workbook1 = Spreadsheet::WriteExcel->new('newproduct.xls'); my $worksheet1 = $workbook1->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"); } }
I know that the variables at the end are storing blank spaces as it goes through all the data. somehow I have to make new variables to store the data that doesn't make a match. that means its a new product code. The product code and the price need to go into the new spreadsheet in the order they are found with no skipped lines. Ive been writing stuff non-stop, I'm so close. I could load the codes and prices that aren't matched into an array and then output them to the spreadsheet in order as suggested by someone, but when I do that, I get syntax errors. I've been at it all day.
Im dyin ova he'a
ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: beating a horse thats not quite dead
by toolic (Bishop) on Jun 05, 2012 at 23:55 UTC | |
|
Re: struggling with spreadsheet::WriteExcel and writing columns
by kcott (Archbishop) on Jun 06, 2012 at 06:19 UTC | |
|
Re: beating a horse thats not quite dead
by thomas895 (Deacon) on Jun 06, 2012 at 00:02 UTC | |
by trickyq (Acolyte) on Jun 06, 2012 at 00:09 UTC |