Chinaunix
标题:
Win32::OLE 连续打开关闭文件无法执行的问题
[打印本页]
作者:
zhn158
时间:
2010-07-19 17:57
标题:
Win32::OLE 连续打开关闭文件无法执行的问题
#!perl -w
use strict;
use 5.010;
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Excel';
$Win32::OLE::Warn = 3;
sub open_excel_file {
my $file_name = shift;
my $excel = Win32::OLE -> GetActiveObject('Excel.Application') ||
Win32::OLE->new('Excel.Application', 'Quit');
my $workbook = $excel -> Workbooks -> Open($file_name);
$workbook -> Close();
}
&open_excel_file("E:/week/test1.xlsx");
&open_excel_file("E:/week/test2.xlsx");
复制代码
报错:
Win32::OLE(0.1709) error 0x80010108: ""
in METHOD/PROPERTYGET "" at E:\week\test.pl line 12
复制代码
如果在第16和17行之间插入:
my $number = 99999;
while ( $number >= 0 ) {
$number--;
}
复制代码
就能正常运行,而且 $number 还不能太小,例如,如果 $number=10000, 就会报错:
Win32::OLE(0.1709) error 0x80010108: "" at E:\week\test.pl line 10
eval {...} called at E:\week\test.pl line 10
main::open_excel_file('E:/week/test2.xlsx') called at E:\week\test.pl line 21
复制代码
这种问题怎么解决呀?期待.....
作者:
ynchnluiti
时间:
2010-07-19 19:51
把 $excel 当成参数传给open_excel_file()?
http://www.perlmonks.org/?node_id=787586
作者:
wxlfh
时间:
2010-07-19 23:21
把Win32::OLE对象放在函数外面,并且当参数传给函数。
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2