需要一些好人帮助我阅读扩展名为“xlsx”的excel文件我的脚本适用于“xls”但不是“xlsx”,这是我得到错误的代码:Can't call method "worksheet" on an undefined value
如果文件是“xlsx”,这是我做有:
#!/usr/bin/perl -w
use warnings;
use strict;
use Spreadsheet::ParseExcel;
use Spreadsheet::XLSX;
use Date::Format;
my $filename = "../test.xlsx";
#Parse excel file
my $parser = Spreadsheet::ParseExcel->new();
my $workbook = $parser->parse("$filename");
#Get cell value from excel sheet1 row 1 column 2
my $worksheet = $workbook->worksheet('Sheet1');
my $cell = $worksheet->get_cell(0,1);
# Print the cell value when not blank
if ( defined $cell and $cell->value() ne "") {
my $value = $cell->value();
print "cell value is $value \n";
}