我的代码似乎没有得到row_range()。它显示错误为:
无法通过包找到对象方法“ row_range” 在clip_init_value.pl第41行的“ Spreadsheet :: ParseExcel :: Worksheet”。
#!/usr/bin/perl
use strict;
use warnings;
use Spreadsheet::ParseExcel;
my $filename = '../../doc/Book1.xls';
my $parser = Spreadsheet::ParseExcel->new();
my $workbook = $parser -> Parse( $filename);
if ( !defined $workbook ) {
die "-E-: cannot parse <$filename>.\n";
}
for my $worksheet ( $workbook-> Worksheet( 'family pin list' ) ) {
# Find out the worksheet ranges
my ( $row_min, $row_max ) = $worksheet->row_range();
my ( $col_min, $col_max ) = $worksheet->col_range();
for my $row ( $row_min .. $row_max ) {
for my $col ( $col_min .. $col_max ) {
# Return the cell object at $row and $col
my $cell = $worksheet->get_cell( $row, $col );
next unless $cell;
print "Row, Col = ($row, $col)\n";
print "Value = ", $cell->value(), "\n";
}
}
}
答案 0 :(得分:2)
要在the answer from TFBW上稍作扩展...
此模块的Changes文件包含以下条目:
0.43 January 7 2009
+ Restructured and rewrote the main documentation. This is the start of
a general refactoring. If you would like to keep up to date with it
keep an eye on the Spreadsheet::ParseExcel Google Group.
http://groups.google.com/group/spreadsheet-parseexcel
+ Added worksheets() Workbook method to iterate over the Worksheet objects.
+ Added unformatted() method to get a Cell's unformatted value.
+ Renamed public methods RowRange(), ColRange() and Cell() to row_range(),
col_range() and get_cell(). Old methods are still available.
! Turned on compatibility_mode() by default in SaveParser to avoid SP3
problems.
! Fixed minor SaveParser bug with font rotation.
http://rt.cpan.org/Public/Bug/Display.html?id=41626
因此,如果模块的版本早于0.43版本,则所需的方法称为RowRange()
。您可以通过在命令行提示符下键入以下内容来找到已安装模块的版本:
perl -MSpreadsheet::ParseExcel -le'print $Spreadsheet::ParseExcel::VERSION'
如果您的模块确实有十多年的历史,那么我强烈建议您对其进行更新。
答案 1 :(得分:1)
是什么版本的Spreadsheet :: ParseExcel :: Worksheet?这些方法过去曾经被命名为RowRange()ColRange()和Cell()。参见https://metacpan.org/changes/distribution/Spreadsheet-ParseExcel