用于读取 excel 文件特定列中所有元素的 perl 脚本
perl script to read all the elements in particular column of an excel file
我编写了一个 perl 脚本来读取 excel 文件中列的特定单元格值。
use strict;
use warnings;
use feature 'say';
use Spreadsheet::Read;
use Spreadsheet::ParseExcel;
my $workbook = ReadData ("C::/Users/Tej/Work.xlsx");
print $workbook->[6]{D4} . "\n";
到这里为止一切都很好。我想编写逻辑来读取 D 列下的所有单元格值,直到该列中有值为止。谁能帮我一下。
谢谢
假设我的数据是:
一种方法是做你想做的(因为 'D' 对应于第 4 列):
$ cat a.pl
use strict;
use warnings;
use feature 'say';
use Spreadsheet::Read;
use Spreadsheet::ParseExcel;
use Data::Dumper;
my $workbook = ReadData ("/tmp/file.xls", parser => "xls");
print Dumper($workbook->[1]{cell}[4]);
foreach my $cell (@{$workbook->[1]{cell}[4]}) {
if ($cell) {
print $cell . "\n";
}
}
$ perl a.pl
$VAR1 = [
undef,
'grid',
1115,
1512,
212
];
grid
1115
1512
212
另一种方法是使用 Spreadsheet::BasicReadNamedCol:
$ cat a.pl
use strict;
use warnings;
use feature 'say';
use Spreadsheet::BasicReadNamedCol;
use Data::Dumper;
my @columnHeadings = (
'grid',
);
my $workbook = new Spreadsheet::BasicReadNamedCol("/tmp/file.xls");
$workbook->setColumns(@columnHeadings);
while (my $data = $workbook->getNextRow()) {
print "@{$data}[0]\n";
}
$ perl a.pl
grid
1115
1512
212
我编写了一个 perl 脚本来读取 excel 文件中列的特定单元格值。
use strict;
use warnings;
use feature 'say';
use Spreadsheet::Read;
use Spreadsheet::ParseExcel;
my $workbook = ReadData ("C::/Users/Tej/Work.xlsx");
print $workbook->[6]{D4} . "\n";
到这里为止一切都很好。我想编写逻辑来读取 D 列下的所有单元格值,直到该列中有值为止。谁能帮我一下。
谢谢
假设我的数据是:
一种方法是做你想做的(因为 'D' 对应于第 4 列):
$ cat a.pl
use strict;
use warnings;
use feature 'say';
use Spreadsheet::Read;
use Spreadsheet::ParseExcel;
use Data::Dumper;
my $workbook = ReadData ("/tmp/file.xls", parser => "xls");
print Dumper($workbook->[1]{cell}[4]);
foreach my $cell (@{$workbook->[1]{cell}[4]}) {
if ($cell) {
print $cell . "\n";
}
}
$ perl a.pl
$VAR1 = [
undef,
'grid',
1115,
1512,
212
];
grid
1115
1512
212
另一种方法是使用 Spreadsheet::BasicReadNamedCol:
$ cat a.pl
use strict;
use warnings;
use feature 'say';
use Spreadsheet::BasicReadNamedCol;
use Data::Dumper;
my @columnHeadings = (
'grid',
);
my $workbook = new Spreadsheet::BasicReadNamedCol("/tmp/file.xls");
$workbook->setColumns(@columnHeadings);
while (my $data = $workbook->getNextRow()) {
print "@{$data}[0]\n";
}
$ perl a.pl
grid
1115
1512
212