Chinaunix

标题: Win32::OLE 连续打开关闭文件无法执行的问题 [打印本页]

作者: zhn158    时间: 2010-07-19 17:57
标题: Win32::OLE 连续打开关闭文件无法执行的问题
  1. #!perl -w
  2. use strict;
  3. use 5.010;
  4. use Win32::OLE;
  5. use Win32::OLE::Const 'Microsoft Excel';
  6. $Win32::OLE::Warn = 3;

  7. sub open_excel_file {
  8.   my $file_name = shift;
  9.   my $excel = Win32::OLE -> GetActiveObject('Excel.Application') ||
  10.       Win32::OLE->new('Excel.Application', 'Quit');
  11.   my $workbook = $excel -> Workbooks -> Open($file_name);
  12.   $workbook -> Close();
  13. }

  14. &open_excel_file("E:/week/test1.xlsx");
  15. &open_excel_file("E:/week/test2.xlsx");
复制代码
报错:
  1. Win32::OLE(0.1709) error 0x80010108: ""
  2.     in METHOD/PROPERTYGET "" at E:\week\test.pl line 12
复制代码
如果在第16和17行之间插入:
  1. my $number = 99999;
  2. while (  $number >= 0 ) {
  3.   $number--;
  4. }
复制代码
就能正常运行,而且 $number 还不能太小,例如,如果 $number=10000, 就会报错:
  1. Win32::OLE(0.1709) error 0x80010108: "" at E:\week\test.pl line 10
  2.         eval {...} called at E:\week\test.pl line 10
  3.         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