无法调用方法“工作表"在一个未定义的值 [英] Can't call method "worksheet" on an undefined value

查看:219
本文介绍了无法调用方法“工作表"在一个未定义的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用相同的perl代码解析excel文件时遇到问题: 我收到此错误:

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

无法在以下位置的未定义值上调用方法工作表" ./parse_pathsim_results.pl第223"

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

有趣的是,如果我在预期的坡度xls文件起作用之前解析了另一个文件(延迟xls),便拥有了perl代码.

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

这是代码:

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");

推荐答案

如果您不提供太多信息,仅提供代码片段,就很难说.

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

最大的怀疑是文件格式本身,因为Parse方法没有返回$workbook,所以解析器返回了undef

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

我最近遇到这样的问题,其中excel文件是一个较新的格式版本. (以.xlsx而不是.xls结尾)使用MS Excel打开文件并将其另存为较旧的excel格式就可以解决问题.

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.

您的第一个文件看起来像是纯CSV文件,因此解析没有问题.

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

这篇关于无法调用方法“工作表"在一个未定义的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆