Thread

Posted on Mon Apr 30 13:36:39 2007 by bosh
how to trap error when parsing corrupted xls file
please help, since I can't find anywhere on how to solve the problem I create a bullet proof script to read xls file because my project will allow users to post any excel file to our web then process the xls to html. problem came when we test to post using corrupted excel file. sure, ms excel 2003 can detect the corrupted file and try to recover the file easily, but not the Spreadsheet-ParseExcel module
$fExcel = Spreadsheet::ParseExcel->new; $wBook = $fExcel->Parse($filename); #parse xls file -> hang on here
it just hang when try to parse, thus forced me to use ctrl-c to stop it is there anyway to trap this kind of error? I need to solve the problem otherwise I can't open the web to public ps: i'm using Win32 Perl
Direct Responses: 5065 | 7226 | Write a response
Posted on Mon May 7 09:07:24 2007 by bosh in response to 5019
Re: how to trap error when parsing corrupted xls file
I got temporary solver just use php module "read xls file", it will generate error after 30 sec time out reading such a corrupted xls file I wonder why that complex perl modules doesn't have some advanced error trapping like php? I still use the perl modules because it far advanced than the php modules the php modules just for testing reading xls purposes only anybody have similar problem?
Direct Responses: 5094 | Write a response
Posted on Wed May 9 07:33:44 2007 by bosh in response to 5065
Re: how to trap error when parsing corrupted xls file
because combining php and perl could lead you into complicated problem (as I did)
ones giving me simple solver, just use time out (alarm) feature

local $SIG{ALRM} = sub { die("TIMED OUT") }; eval { alarm(20); #set our alarm for 20 seconds $wBook = $fExcel->Parse($filename); #parse xls file alarm(0); }; if ( $@ =~ /TIMED OUT/ ) { print "file $filename load error! time out on processing, could be corrupt!\n"; goto ended; }; not_ended_runs_here: ....

it solved my problem!
it uses same concept as php module which I try before, that php module also use timeout feature too
Write a response
Posted on Fri Feb 29 07:16:42 2008 by fyz in response to 5019
Re: how to trap error when parsing corrupted xls file
Hi, I think you can try a popular Excel file recovery tool called Advanced Excel Repair to repair your Excel file. It is a powerful tool to repair corrupt or damaged Excel files. Detailed information about Advanced Excel Repair can be found at http://www.datanumen.com/aer/ And you can also download a free demo version at http://www.datanumen.com/aer/aer.exe Alan
Write a response