当前位置: 代码迷 >> CGI >> 关于perl操作Excel的有关问题
  详细解决方案

关于perl操作Excel的有关问题

热度:387   发布时间:2012-03-11 18:15:39.0
关于perl操作Excel的问题
下面是我从网上抄来的代码,但是在我的机器上总是无法运行,不知道是什么原因。
请高手指点!

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'创建成功了吗?
  相关解决方案