Excel(一)Spreadsheet::ParseExcel

来源:互联网 发布:linux oracle查看实例 编辑:程序博客网 时间:2024/05/01 23:38

例子:

#usr/bin.perl -wuse strict;use SpreadSheet::ParseExcel;#Be used to  read excel informationuse 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




原创粉丝点击