Hello there. I need to seek the Wisdom of a monk with
knowledge of Excel. I'm using the Spreadsheet::ParseExcel
::Simple module to search through a fairly straightforward
Excel spreadsheet. The problem comes when I encounter a
blank cell. I want to read the contents of the cell into
a simple list array, based on whether or not it is empty.
If the cell is empty, I want to insert an "X" instead.
However, despite stripping the contents of "empty" cells
of all whitespace, carriage returns and new line
characters, *sometimes* Perl still seems to think there is
something in it. If I go into Excel and manually change
the font on the empty cells, the problem goes away. Also,
the cells that seem to evaluate incorrectly are always
the last item in the current row. Any help with this
problem would be appreciated. I think it's something to do
with an invisible control character evaluating as a
non-whitespace character for some reason.
Here is a snippet of code:
$excelfile = "/data/MS/excel/contract_check.xls";
$xls = Spreadsheet::ParseExcel::Simple->read($excelfile);
@sheets = $xls->sheets;
while ($sheets[1]->has_data)
{
@hsbcdata = ();
@hsbcdataread = $sheets[1]->next_row;
foreach $_ (@hsbcdataread)
{
s/^\s*//;
s/\s*\r*$//;
chomp ($_);
if (/\S+/)
{
push (@hsbcdata, $_);
}
else
{
push (@hsbcdata, "X"); #
}
}
...
}
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.