下面是我从网上抄来的代码,但是在我的机器上总是无法运行,不知道是什么原因。
请高手指点!
use strict;
use Win32::OLE;
print"Content-type:text/html\n\n";
my $excel;
eval {
Win32::OLE->GetActiveObject('Excel.Application');
};
if ($@) {
print "没有安装Excel。 $@";
}
unless (defined $excel) {
$excel = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;})
or print "Excel不能启动。";
}
my $book = $excel->Workbooks->Add;
my $sheet = $book->Worksheets(1);
$sheet->Cells(1, 1)->{Value} = "数字";
foreach my $i (2 .. 11) {
$sheet->Cells($i, 1)->{Value} = $i - 1;
}
my $file = 'C:\test.xls';
unlink $file;
$book->SaveAs($file);
$book->Close();
$excel->Quit();
------解决方案--------------------
无法运行 ?那么'Excel.Application'创建成功了吗?