perl - 无法在 perl 脚本中获取 row_range
问题描述
我的代码似乎没有得到 row_range()。它显示一个错误,即:
无法通过 clamp_init_value.pl 第 41 行的包“Spreadsheet::ParseExcel::Worksheet”定位对象方法“row_range”。
#!/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";
}
}
}
解决方案
稍微扩展TFBW 的答案......
此模块的更改文件包括以下条目:
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'
如果您确实有一个超过十年的模块版本,那么我强烈建议您更新它。
推荐阅读
- reactjs - 在 nextJS 开发版本中出现“找不到模块”错误
- html - 如何更改日期输入html标签的占位符的颜色?
- selenium - XPATH - 为什么 text() 函数中的括号
- javascript - 将组件反应到功能组件
- flutter - 我们是否应该对 build_runner 为 mockito 创建的 .mocks.dart 文件进行源代码控制
- javascript - React js中的图片方向从纵向更改为横向
- java - Java If Else 语句不会为子字符串触发
- css - 使用全尺寸标题颜色填充创建 Rad 窗口
- python - 对象所有者与外键对象约束相同
- python-3.x - GithubApi 通过 org 私有 repo 读取 Files 的内容