我正在尝试从 excel 文件(可以是 xlsx 或 xls)中解析数据。
我已经知道我想要获得哪些工作表,所以我想遍历它们并从中提取数据。
我的代码:
#!/usr/bin/perl -w
use strict;
use warnings;
use Spreadsheet::Read;
use Getopt::Long;
my $inputfile;
GetOptions (
'i=s' => \$inputfile,
);
die 'missing input file' unless $inputfile;
my $workbook = ReadData ($inputfile, debug => 9);
my @worksheets = (1);
foreach (@worksheets) {
my $sheet = $workbook->[$_-1];
next unless $sheet;
my ( $row_min, $row_max ) = $sheet->row_range();
my ( $col_min, $col_max ) = $sheet->col_range();
for my $row ($row_min .. $row_max) {
}
}
但是,我得到以下信息:
Can't call method "row_range" on unblessed reference at perl/parse_test.pl line 22.
我对 perl 很陌生,还不了解散列、数组和引用的复杂性。