用Perl生成EXCEL文件的简单例子

980阅读 0评论2010-08-30 zhengsenlin888
分类:

#!/usr/bin/perl
#Author ATGC

use strict;
use Win32::OLE;
my $excel_file = 'c:/out.xls';
my ($row,@field,$c_times,$residual,$cols,$cell_end);
my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit');
my $Book = $Excel->Workbooks->add;
my $Sheet = $Book->Worksheets(1);
my @array_cols=("Z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
unlink $excel_file if (-e $excel_file);
@field=("你好","他好","大家好","就我不好");

$cols=scalar(@field);
$c_times=sprintf "%.0f",$cols/26+0.5;
$residual=$cols%26;
$cell_end = ($cols<27) ? $array_cols[$cols] : $array_cols[$c_times-1].$array_cols[$residual];
$row++;
$Sheet->Range("A$row:$cell_end$row")->{Value} = [@field];
$Book->SaveAs($excel_file);
undef($Sheet);
undef($Book);
undef($Excel);


上一篇:linux虚拟机和windows xp连接不上
下一篇:[简洁Perl指南II]PERL程序的示例与浅析