Are you sure that the cell actually exists? I seem to recall having an issue like this last year, where some cells never had a value and didn't exist. If I recall correctly, merged cells had their neighbors missing, too. I don't have a copy of Excel to double-check it (or the final version of the program, it's on a different machine), but here's a fragment of an earlier version where I was reading from the spreadsheet:

sub get_worksheet_data { my $worksheet = shift; my ($row_min, $row_max) = $worksheet->row_range(); my ($col_min, $col_max) = $worksheet->col_range(); my @data; # Read sheet into array for my $row ($row_min .. $row_max) { for my $col ($col_min .. $col_max) { my $cell = $worksheet->get_cell($row, $col); next unless defined $cell; # Try to detect dates my $v = $cell->value(); my $u = $cell->unformatted(); my $T = $cell->{Type}; my $result = $T;

See that "next unless defined $cell;" statement? If memory serves, I had the same issue you seem to be encountering, where cells don't necessarily exist. In my project, I had a post-processing phase where I copied the value from the previous row into the cell whenever I found a missing cell. (It was a human-readable report, so that was the expected input: blanks meant "same as the row above".)

The "Try to detect dates" section was heinous (omitted) as there were multiple date formats people used (and they weren't always actual dates. That was one of the most annoying parts of the project.

The *most* annoying part of the project is that the XLSX parser is so much slower than the binary file parser. (It took somewhere between two and three *minutes* to parse the spreadsheet. It wasn't a terribly large spreadsheet.)

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re: Spreadsheet::ParseXLSX or Spreadsheet::ParseExcel doesn't work with .xlsx by roboticus
in thread Spreadsheet::ParseXLSX or Spreadsheet::ParseExcel doesn't work with .xlsx by Anonymous Monk

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, 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, 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.