- 论坛徽章:
- 0
|
粘一个自己平时用的,希望有所帮助。
#!/usr/bin/perl -w
## Program : xls.pl
## Version : 1.0
## Date : 2010.7.8
##------------------------------------------------------------------------------
use Spreadsheet: arseExcel;
use Spreadsheet: arseExcel::FmtUnicode;
use Spreadsheet::WriteExcel;
#---------------------------写EXCEL-------------------------------------------------------
my $output= File::Spec->catfile('Copy.xls');
my $Map=new Unicode::Map("GB2312" ;
my $workbook=Spreadsheet::WriteExcel->new("$output" ;
my $out_worksheet=$workbook->add_worksheet("table" ;
$format = $workbook->add_format(align=>'center',bg_color=>'cyan',border=> 1);
#---------------------------读取EXCEL-------------------------------------------------------
$filename="input.xls";
my $oExcel = new Spreadsheet: arseExcel;
my $code = "gb2312";
my $oFmtJ = Spreadsheet: arseExcel::FmtUnicode->new(Unicode_Map =>$code);
my $oBook = $oExcel-> arse( $filename, $oFmtJ );
my $sheet=$oBook->{Worksheet}[0];
#$sheet_name=$sheet->{Name};
my ( $minRow, $maxRow ) = $sheet->row_range();
my ( $minCol, $maxCol ) = $sheet->col_range();
my @rowdata;
my $r_num=0;
for $r(0..$maxRow){
@row_data=getSingleRow($r,$maxCol,$sheet);
#print "@row_data"."\n";
my $i=0;
foreach(@row_data){
print $_;
$out_worksheet->write_unicode($r,$i++,$Map->to_unicode($_),$format);
}
}
sub getSingleRow{
my($row,$maxCol,$sheet)=@_;
my @row_all;
foreach my $col ( 0 .. $maxCol ){
my $cell = $sheet->get_cell( $row, $col );
next unless $cell;
$data=$cell->value;
push(@row_all,$data);
}
return @row_all;
} |
|