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!
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.