Sunday, March 05, 2006

Spreadsheet::ParseExcel Warnings

An unresolved bug exists in the Perl module Spreadsheet::ParseExcel version 0.2603, which causes warnings to be displayed
Character in 'c' format wrapped in pack at /usr/lib/perl5/vendor_perl/5.8.6/Spreadsheet/ line 1790.
Character in 'c' format wrapped in pack at /usr/lib/perl5/vendor_perl/5.8.6/Spreadsheet/ line 1789.
While the warnings do not cause errors in the module output they are irritating when parsing large spreadsheets. A workaround involves changing basic changes to the two lines of code:

substr($sWk, 3, 1) &= pack('c', unpack("c",substr($sWk, 3, 1)) & 0xFC);
substr($lWk, 0, 1) &= pack('c', unpack("c",substr($lWk, 0, 1)) & 0xFC);
substr($sWk, 3, 1) &= pack('C', unpack("C",substr($sWk, 3, 1)) & 0xFC);
substr($lWk, 0, 1) &= pack('C', unpack("C",substr($lWk, 0, 1)) & 0xFC);
Essentially, you are changing the lowercase "c" to capital "C", in all instances in the two lines. The error is caused by the module attempting to mask the last two bits of the character by unpacking it to a signed number, masking 0xFC, and then repacking it to a signed number. By changing, the letter the same operation is performed using unsigned integers.

No comments: