介绍两个perl中的两个包,分别可以读取Excel的文件,包括2003 的xls文件Spreadsheet::ParseExcel,和2007的xlsx的文件Spreadsheet::ParseXLSX。
use Spreadsheet::ParseExcel;
#读取Excel2003版本的excel文件
my $parser = Spreadsheet::ParseExcel->new();
my $workbook = $parser->parse('test.xls');
if ( !defined $workbook ) {
die $parser->error(), ".\n";
}
my $worksheet = $workbook->worksheet('Sheet1');
my ( $row_min, $row_max ) = $worksheet->row_range();
my ( $col_min, $col_max ) = $worksheet->col_range();
printf "%15s %15s %15s",'first_row','second_row','third_row'."\n";
for my $row ( $row_min .. $row_max ) {
for my $col ( $col_min .. $col_max ) {
my $cell = $worksheet->get_cell( $row, $col );
next unless $cell;
my $va=$cell->value();
printf "%15s",$va;
}
say;
}
use Spreadsheet::ParseXLSX;
#读取Excel2007版本的excel文件 用法差不多
my $parser = Spreadsheet::ParseXLSX->new;
my $workbook = $parser->parse("file.xlsx");
my $worksheet = $workbook->worksheet('Sheet1');
my ( $row_min, $row_max ) = $worksheet->row_range();
my ( $col_min, $col_max ) = $worksheet->col_range();
printf "%15s %15s %15s",'first_row','second_row','third_row'."\n";
for my $row ( $row_min .. $row_max ) {
for my $col ( $col_min .. $col_max ) {
my $cell = $worksheet->get_cell( $row, $col );
next unless $cell;
my $va=$cell->value();
printf "%15s",$va;
}
say;
}
use Spreadsheet::WriteExcel; |
use Excel::Writer::XLSX; |
https://metacpan.org/pod/Excel::Writer::XLSX#Excel::Writer::XLSX-and-Spreadsheet::WriteExcel
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!