Use spreadsheet in CPAN::P arseexcel module to read the contents of the Excel file, when encountering Chinese garbled problem, use spreadsheet::P arseexcel::fmtunicode module recoding, When assigning Chinese to a variable, the Encode module is decoded by GB2312.
use strict;
use Spreadsheet::ParseExcel;
use Spreadsheet::ParseExcel::FmtUnicode;
use Encode;
my $oFmtC=Spreadsheet::ParseExcel::FmtUnicode->new(Unicode_Map=>"CP936");
my $parser=Spreadsheet::ParseExcel->new();
my $workbook=$parser->parse(‘test.xls‘,$oFmtC);
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<=$row_max;$row++){
for (my $col=$col_min;$col<=$col_max;$col++){
my $cell = $worksheet->get_cell($row,$col);
$a=$cell->value();
$a=decode("gb2312",$a);
#do something
}
}
This article is from "Ruyi Spirit Pro" blog, please be sure to keep this source http://417722381.blog.51cto.com/7856838/1880722
Perl reads Excel files and solves Chinese garbled problems