An alternative would be to test the file type first and then choose the correct parser. For example
poj#!/usr/bin/perl use strict; use File::MMagic; use Spreadsheet::ParseXLSX; use Spreadsheet::ParseExcel; my $FileToOpen = 'c:/temp/myfile.xlsx'; my $ft = File::MMagic->new(); my $type = $ft->checktype_filename($FileToOpen); my $parser; if ($type =~ /zip/){ $parser = Spreadsheet::ParseXLSX->new(); } else { $parser = Spreadsheet::ParseExcel->new(); } my $workbook = $parser->parse($FileToOpen); if ( !defined $workbook ) { die $parser->error(), ".\n"; } printf "%s has %d sheets\n",$FileToOpen,$workbook->worksheet_count();
In reply to Re: trap error from parsexlsx
by poj
in thread trap error from parsexlsx
by gauss76
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |