標籤:style class blog code http tar
因為工作當中遇到要處理大資料的excel的玩意,最多的有幾十萬行。用perl的方式試試,看看效果如何。
ppm install OLE::Storage_Lite #如果不安裝這個,後面兩個安裝不了 ppm install Spreadsheet::ParseExcelppm 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);
View Code
記錄下,明天去公司試試效果