I have one final question concerning spreadsheet::xlsx

I have been writing a price list updater and with help and alot of reading I have a pretty badass little script. Thank you to all

my next question should be reasonably simple. Of Course its the things that seem the most simple that I seem to struggle with.

Heres the script so you can see what I am talking about

#!/usr/bin/perl use strict; use Spreadsheet::XLSX; my $excel = Spreadsheet::XLSX -> new ('build.xlsx'); my $sheet = $excel->Worksheet('Sheet1'); my ($row_min,$row_max) = $sheet->row_range(); my %colD=(); for my $row ($row_min..$row_max){ my $valD = $sheet->{Cells}[$row][3]->{Val}; $colD{$valD} = $row+1; # excel row number } open FILE,'>','feckyou.txt' or die $!; 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"; } 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; } }

In the if statement above it takes any instance of a new product id in colA and looks for it in colD. if it finds it anywhere in ColD it puts it in a text file. I need it to take the price it finds in ColB, which is also currently printing to the text file. I need to print that value (the price in colB) to Column R in the corresponding row with column A.

So, if Column A6 has a product code of 12345 and the script finds a match all the way on Column D2341, it will write the price from Column B6 to Column R6.

I cannot find the syntax for writing back to an Excel spreadsheet using Spreadheet::xlsx

thank you

ken


In reply to How Do I Write an Excel Spreadsheet using Spreadsheet::XLSX 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.