|
楼主 |
发表于 2011-8-25 22:55:39
|
显示全部楼层
#! /usr/bin/perl -w
use Spreadsheet::WriteExcel;
#************生成Excel文档****************
my $xl = Spreadsheet::WriteExcel->new("TEST.xls");
#生成Excel表
my $xlsheet = $xl->add_worksheet("TestSheet");
#添加格式(表头)
$rptheader = $xl->add_format(); # Add a format
$rptheader->set_bold();
$rptheader->set_size('12');
$rptheader->set_align('center');
#添加格式(表内容)
$normcell = $xl->add_format(); # Add a format
$normcell->set_size('17');
$normcell->set_align('center');
$normcell->set_bg_color('17');
#$normcell->set_bg_color('$i');
#设置列的宽度
$xlsheet->set_column('A:A',17);
$xlsheet->set_column('B:B',17);
$xlsheet->set_column('C:C',17);
$xlsheet->set_column('D',17);
#写表头(格式是使用上面添加的表头格式)
$xlsheet->write("A2","Number", $rptheader);
$xlsheet->write("B2","Name",$rptheader);
$xlsheet->write("C2","Language",$rptheader);
##写内容(格式是使用上面添加的表内容格式)
#$xlsheet->write("A3","1", $normcell);
#$xlsheet->write("B3","Test",$normcell);
#$xlsheet->write("C3","erl",$normcell);
#关闭操作excel的对象.
#$xl->close();
#************生成Excel完成****************
$i=3;
open IN,"sn"||die "can not open the file !\n";
while (<IN>) {
@a = split(/ +/,$_);
#print @a;
#for $a (@a) {
$xlsheet->write("A$i","$a[0]",$normalcell);
$xlsheet->write("B$i","$a[1]",$normalcell);
$xlsheet->write("C$i","$a[2]",$normalcell);
$xlsheet->write("D$i","$a[3]",$normalcell);
#}
$i++;
}
$xl->close(); |
|