我有一个包含许多列的Excel文件,但我只需要对其中的3列进行一些计算。
我正在使用SpreadSheet::ParseExcel
来遍历我的Excel文件。如何使用perl指定我想要的列?
答案 0 :(得分:4)
#!/usr/bin/perl -w
use strict;
use Spreadsheet::ParseExcel;
my $parser = Spreadsheet::ParseExcel->new();
my $workbook = $parser->parse('Book1.xls');
if ( !defined $workbook ) {
die $parser->error(), ".\n";
}
for my $worksheet ( $workbook->worksheets() ) {
my ( $row_min, $row_max ) = $worksheet->row_range();
my @columns = (1,5,6) # enter your 3 columns here
for my $row ( $row_min .. $row_max ) {
for my $col (@columns) {
my $cell = $worksheet->get_cell( $row, $col );
next unless $cell;
# do the calculations here
print "Row, Col = ($row, $col)\n";
print "Value = ", $cell->value(), "\n";
print "Unformatted = ", $cell->unformatted(), "\n";
print "\n";
# operations done
}
}
}
来源:Spreadsheet::ParseExcel模块的文档。