全部博文(362)
分类:
2010-08-30 14:45:08
#!/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);