例子:
#usr/bin.perl -w
use strict;
use SpreadSheet::ParseExcel;#Be used to read excel information
use SpreadSheet::ParseExcel::FmtUnicode;
use Unicode::Map;
my $formatter = Spreadsheet::ParseExcel::FmtUnicode -> new(Unicode_Map=>"CP936");
my $parser = Spreadsheet::ParseExcel->new();
my $workbook = $parser->parse('example.xls',$formatter);
if ( !defined $workbook ) {
die $parser->error(), ".\n";
}
for my $worksheet ( $workbook->worksheets() ) {
my ( $row_min, $row_max ) = $worksheet->row_range();
my ( $col_min, $col_max ) = $worksheet->col_range();
for my $row ( $row_min .. $row_max ) {
for my $col ( $col_min .. $col_max ) {
my $cell = $worksheet->get_cell( $row, $col );
next unless $cell;
print "Row, Col = ($row, $col)\n";
print "Value = ", $cell->value(), "\n";
print "Unformatted = ", $cell->unformatted(), "\n";
print "\n";
}
}
}
结果:
要点:
中文处理:
unicode::Map, spreadsheet::ParseExcel::FmtUnicode -> new(Unicode_Map => "CP936")
对象的理解:
workbook, worksheet, cell, format
详细请参照 http://search.cpan.org/~jmcnamara/Spreadsheet-ParseExcel-0.59/lib/Spreadsheet/ParseExcel.pm