![](/img/trans.png)
[英]Replace a pattern in file with the header of that specific column with perl
[英]column header in excel file with Perl
我有一个包含许多列的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
}
}
}
来源: Spreadsheet :: ParseExcel模块的文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.