标签:style class blog code http tar
因为工作当中遇到要处理大数据的excel的玩意,最多的有几十万行。用perl的方式试试,看看效果如何。
ppm install OLE::Storage_Lite #如果不安装这个,后面两个安装不了 ppm install Spreadsheet::ParseExcel ppm install Spreadsheet::WriteExcel
查看是否安装成功
perldoc Spreadsheet::ParseExcel #如果打印出文档则表示安装成功
为保证编码正确
ppm install Unicode::Map
use strict; use Spreadsheet::ParseExcel; use Spreadsheet::ParseExcel::FmtUnicode; #字符编码 my $parser = Spreadsheet::ParseExcel->new(); my $formatter = Spreadsheet::ParseExcel::FmtUnicode->new(Unicode_Map=>"CP936");#设置字符编码 #my $workbook = $parser->parse(‘Book.xls‘); my $workbook = $parser->parse(‘E:\webdev\project\perl\a.xls‘, $formatter);#按所设置的字符编码解析 my $log = "demo.log"; if ( !defined $workbook ) { die $parser->error(), ".\n"; } open(FILE,">$log"); 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 $cell->value()," "; print(FILE $cell->value()."\t"); } print "\n"; print(FILE "\n"); } } close(FILE);
记录下,明天去公司试试效果
标签:style class blog code http tar
原文地址:http://www.cnblogs.com/yimiao/p/3807032.html