Windows Perl+;Excel:“;使用Win32::OLE::Const“;没有效果

Windows Perl+;Excel:“;使用Win32::OLE::Const“;没有效果,windows,perl,ole,win32ole,strawberry-perl,Windows,Perl,Ole,Win32ole,Strawberry Perl,我一直在使用StrawberryPerlV5.014和Win32::OLE在Windows7系统上进行一个项目 我正在尝试使用第二台运行WindowsXPSP3的电脑,来并行开发同一个项目。在新系统上,我安装了草莓Perl v 5.016,并使用cpanp安装Win32::OLE和Win32::OLE::Const 我在新系统中使用相同的脚本源 事实证明,在新系统中 use Win32::OLE::Const 'Microsoft Excel'; 没有效果。我得到一个错误: Bareword

我一直在使用StrawberryPerlV5.014和Win32::OLE在Windows7系统上进行一个项目

我正在尝试使用第二台运行WindowsXPSP3的电脑,来并行开发同一个项目。在新系统上,我安装了草莓Perl v 5.016,并使用cpanp安装Win32::OLE和Win32::OLE::Const

我在新系统中使用相同的脚本源

事实证明,在新系统中

use Win32::OLE::Const 'Microsoft Excel';
没有效果。我得到一个错误:

Bareword "xlExcel8" not allowed while "strict subs" in use in StatementExcel.pm line 159.
这个错误没有出现在我提到的第一个原始系统中

怎么办

蒂娅,海伦

以下是该节目的一些摘录:

package  StatementExcel;
require  Exporter;
@ISA   = qw(Exporter);
@EXPORT  = qw(LoadExcel ProcessPreparedSheet);
use strict;
use warnings;
use Encode;
use 5.016;
use utf8;
use Win32::Console;
use autodie; 
use warnings    qw< FATAL  utf8     >;
use StateConversion;
use Carp;
use Win32::OLE  qw(CP_UTF8);
use Win32::OLE::Const 'Microsoft Excel';
use Cwd;
use Text::CSV::Unicode;
use File::BOM qw( :all );
use List::MoreUtils 'first_index';
...
$xlBook -> SaveAs( $xlFile, xlExcel8);

$i = Win32::OLE->LastError();
if ($i) {
   PrintT $parms{LogStructRef}{HANDLE}, "Error trying to save Excel file:\n", $i;
}   # end if ($i)
PrintT $parms{LogStructRef}{HANDLE}, 'Press <return> to continue...';   # Wait for user input...
$j = <STDIN>;
# Clean up
$xlBook->{Saved} = 1;
$xlApp->Quit;
$xlBook = 0;
$xlApp = 0;
...
package语句excel;
要求出口商;
@ISA=qw(出口商);
@导出=qw(加载Excel ProcessPreparedSheet);
严格使用;
使用警告;
使用编码;
使用5.016;
使用utf8;
使用Win32::Console;
使用自动模具;
使用警告qw;
使用状态转换;
使用鲤鱼;
使用Win32::OLE qw(CP_UTF8);
使用Win32::OLE::Const“Microsoft Excel”;
使用化学武器;
使用Text::CSV::Unicode;
使用文件::BOM qw(:全部);
使用列表::MoreUtils“第一个索引”;
...
$xlBook->SaveAs($xlFile,xlExcel8);
$i=Win32::OLE->LastError();
如果有的话(一美元){
PrintT$parms{LogStructRef}{HANDLE},“试图保存Excel文件时出错:\n”,$i;
}#如果结束($i)
PrintT$parms{LogStructRef}{HANDLE},'按继续…'#等待用户输入。。。
$j=;
#清理
$xlBook->{Saved}=1;
$xlApp->退出;
$xlBook=0;
$xlApp=0;
...

注意:在PerlMonks上交叉发布:

结果表明,出现问题的原因是Excel 2010和Excel 2003之间的OLE对象库存在差异。 在Win XP系统上,安装了Excel 2003。在Windows 7系统上,安装了Excel 2010。保存Excel文件时,我指示它使用“xlExcel8”OLE常量将其保存为Excel 2003“xls”格式(而不是Excel 2010的“xlsx”格式)

事实证明,OLE 2003对象库中不存在此常量

解决方案很简单:保存文件而不指定格式-它使用默认格式

另见: