Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi there Monks!
I am writing a Perl script to parse a 2007 .xlsx file and got stuck on this line :
printf("( %s , %s ) => %s<br>", $row, $col, $cell -> {Val});

I am trying to get the values of my two columns spreadsheet into the $name_val and $address_val variables cause I'll need to store them into a database. Here is a sample code, some from the documentation on the module I am using for this:
... my $f_to_parse = "accounts.xlsx"; my $excel = Spreadsheet::XLSX->new($f_to_parse) or die "could not rea +d the excel: $@$!"; foreach my $sheet (@{$excel -> {Worksheet}}) { printf("Sheet: %s<br>", $sheet->{Name}); $sheet -> {MaxRow} ||= $sheet -> {MinRow}; # Skip worksheet if it doesn't contain data. next if $sheet -> {MinRow} > $sheet -> {MaxRow}; foreach my $row ($sheet -> {MinRow} .. $sheet -> {MaxRow}) { $sheet -> {MaxCol} ||= $sheet -> {MinCol}; foreach my $col ($sheet -> {MinCol} .. $sheet -> {MaxCol} +) { my $cell = $sheet -> {Cells} [$row] [$col]; if ($cell) { printf("( %s , %s ) => %s<br>", $row, $col, $cell -> { +Val}); my $name_header = $cell -> {Val} if $cell -> {Val} + =~m/\bName\b$/i; my $address_header = $cell -> {Val} if $cell -> {Val} + =~m/\bAddress\b$/i; #my $name_val = $sheet->{Cells}[$col][0]->{Val}; #my $address_val = $sheet->{Cells}[$row][0]->{Val}; print "\n\n Test Results:::174^^$name_val -> $address_ +val\n"; } } } }

Thanks for the help!

Replies are listed 'Best First'.
Re: Spreadsheet::XLSX Values into DB Help!
by runrig (Abbot) on Jul 25, 2012 at 22:58 UTC
    Why are you stuck on that line?
      This should mean what you are looking for:
      ... foreach my $col ($sheet -> {MinCol} .. $sheet -> {MaxCol}) { my $cell = $sheet -> {Cells} [$row] [$col]; if ($cell) { #printf("( %s , %s ) => %s<br>", $row, $col, $cell -> +{Val}); my $name_val = $sheet->{Cells}[$row][0]->{Val}; my $address_val = $sheet->{Cells}[$row][1]->{Val}; print "\n\n Test Results::: $name_val -> $address_val\ +n"; } } ...
        Well, I wasn't looking for anything, except a reason why the OP was stuck on a line of code, and I don't understand how your answer means that, but thanks anyway...