I have one final question then this project is done

I am having trouble writing to the spreadsheet that the data comes from. Let me explain. I use spreadsheet::xlsx to read two columns from a spreadsheet called build.xlsx. It then compares column A with column D. If there is a match that means there is a price change on that product ID. If not, the product is new. The new products write to a new spreadsheet (per my last post that I got yelled at for reposting) and that works. If there is a match which indicates a price change, then I need the script to write the price from column B to column R (17) in the same spreadsheet. here's the code.

#!/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(); my $write_row = 1; for my $row (1..$row_max){ my $valA = $sheet->{Cells}[$row][0]->{Val}; my $valB = $sheet->{Cells}[$row][1]->{Val}; # does this value exist in Col D if (exists $colD{$valA}) { my $xlrow = $row+1; #this is where it would write to column R print FILE "price change [A$xlrow]=[D$colD{$valA}] Value=$valB\n"; } else { #output new products to text file # ... $worksheet1->write ($write_row, 0, "$valA"); $worksheet1->write ($write_row, 1, "$valB"); $write_row++; # ... } }

When i try to write to that sheet in that column using

$sheet->write ($write_row, 17, "$valB:);

in place of the txt file it is currently writing to, it errors out. Not sure if there is some way i need to somehow redeclare it or if its locked out from the earlier declaration. It seems like it should be easy.

this is not the same question. same script, totally different problem

thanks


In reply to Writing to a spreadsheet that the data came from 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.