我有一个包含许多列的 Excel 文件,但我只需要对其中的 3 列进行一些计算。
我SpreadSheet::ParseExcel
用来遍历我的 Excel 文件。如何使用 perl 指定我想要的列?
#!/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
}
}
}