Can't call method “worksheet” on an undefined

2019-09-06 03:36发布

I have a problem parsing excel file in the same perl code: I get this error:

"Can't call method "worksheet" on an undefined value at ./parse_pathsim_results.pl line 223"

Interestingly in the perl code I have if I parse another file (delay xls) before the intended slope xls file it works.

Here is the code:

use Spreadsheet::ParseExcel::SaveParser;  
$input_delay_csv_file = "./presto/prs/c2x_delay.xls";
$input_slope_excel_file = "./presto/prs/c2x_slope.xls";
$slope_parser = Spreadsheet::ParseExcel::SaveParser->new();
$delay_parser = Spreadsheet::ParseExcel::SaveParser->new();

The code works if I use the following two lines, but I don't want to.

$workbook = $delay_parser->Parse("$input_delay_csv_file");  
$worksheet = $workbook->worksheet("Sheet1");

This is where it creates a problem if the above two lines are commented.

$new_workbook = $slope_parser->Parse("$input_slope_excel_file");   
$worksheet = $new_workbook->worksheet("Sheet1");

1条回答
Viruses.
2楼-- · 2019-09-06 04:34

Without you giving much information and only snippets of your code it is hard to say.

The great suspect is the file format itself, as the Parse method does not return a $workbook, the parser returned undef

I recently had a problem like this where the excel file was a quite recent format version. (ending on .xlsx and not .xls) Opening the file with MS Excel and saving as an older excel format did the trick.

Your first file looks as if it was a plain CSV file, and therefore had no problem parsing.

查看更多
登录 后发表回答