The Spreadsheet::ParseExcel::Simple next_row() method subclasses the Spreadsheet::ParseExcel Cell->Value() method to retrieve data from an Excel row.

If a cell is blank then Spreadsheet::ParseExcel::Cell::Value returns an undef which Spreadsheet::ParseExcel::Simple::next_row turns into a empty string for convenience.

So far so good. Where I think the problem arises is between what you perceive as a blank cell and what Excel perceives as a blank cell.

Excel differentiates between an empty cell and a blank cell. An empty cell is a cell which doesn't contain data whilst a blank cell is a cell which doesn't contain data but does contain formatting. Excel stores blank cells but ignores empty cells.

To add to the confusion a cell that was formatted at some stage but now has its formatting removed may still have some internal flags set that aren't visible to the user. This would result in blank cell instead of an empty cell. You can remove these using Edit->Clear->All in Excel.

As such all of your s/// and chomp code is to no avail. Probably the best thing to do is just remove any empty strings from the end of the array returned by next_row():

@hsbcdataread = $sheets[1]->next_row(); pop @hsbcdataread while @hsbcdataread and $hsbcdataread[-1] eq "";

--
John.


In reply to Re: Perl and Excel by jmcnamara
in thread Perl and Excel 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, 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.