Spreadsheet::ParseExcel
Spreadsheet::WriteExcel
===============================粘一個自己平時用的,希望有所説明。 #!/usr/bin/perl -w
## Program : xls.pl
## Version : 1.0
## Date : 2010.7.8
##------------------------------------------------------------------------------ use Spreadsheet:ParseExcel;
use Spreadsheet:ParseExcel::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:ParseExcel;
my $code = "gb2312";
my $oFmtJ = Spreadsheet:ParseExcel::FmtUnicode->new(Unicode_Map =>$code);
my $oBook = $oExcel->Parse( $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;
}==============================================
1 #!/usr/bin/perl
2
3 use strict;
4 use Spreadsheet::ParseExcel;
5
6 my $parser = Spreadsheet::parseExcel->new();
7 my $workbook = $parser->Parse($ARGV[0]);
8
9 for my $worksheet($workbook->worksheets()){
10 my ($row_min,$row_max)=$worksheet->row_range();
11 my ($col_min,$col_max)=$worksheet->col_range();
12
13 for my $row($row_min .. $row_max){
14 for my $col($col_min .. $col_max){
15 my $cell=$worksheet->get_cell($row,$col);
16 next unless $cell;
17 print "Row,Col = ($row,$col)\n";
18 print "Value =",$cell->value(),"\t\n";
19 print "Unformatted = ",$cell->unformatted(),"\n";
20 print "\n";
21 }
22 }
23 }
創作者介紹
創作者 shadow 的頭像
shadow

資訊園

shadow 發表在 痞客邦 留言(0) 人氣()