Spreadsheet :: Read和columns

时间:2015-11-16 19:20:29

标签: perl

我尝试使用Perl的Spreadsheet :: Read提取电子表格各列中的所有数据。例如,我想提取以下列中的所有数据:

A1 = 'NewRecordFlag'
B1 = 'AgencyName'
C1 = 'CredentialIdnt'

在Spreadsheet :: Read模块中,我可以从行中提取所有数据但是如何从列中提取?

在下面的示例中,下面的代码是从第6行提取数据。那么,如何创建A1,B1和C1的数组?

#!/usr/bin/perl
use warnings;
use strict;

use Data::Printer;
use Spreadsheet::Read qw(row rows);
use Spreadsheet::Read;



my $workbook = ReadData("test.xls");

my @row = row($workbook->[1], 6);

1 个答案:

答案 0 :(得分:0)

我能够使用Spreadsheet::BasicReadNamedCol模块

解决此问题
#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;
use Spreadsheet::BasicReadNamedCol;

my $xlsFileName = 'test.xls';
my @columnHeadings = (
'AgencyName',
'eMail',
'PhysicalAddress1',
'PhysicalAddress2'
);

my $ss = new Spreadsheet::BasicReadNamedCol($xlsFileName) ||
die "Could not open '$xlsFileName': $!";
$ss->setColumns(@columnHeadings);

# Print each row of the spreadsheet in the order defined in
# the columnHeadings array
my $row = 0;
while (my $data = $ss->getNextRow())
{
$row++;
print join('|', $row, @$data), "\n";
}