首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用PERL和Win32::OLE在命令行上操作Word文档,但不能从BuildForge步骤操作

使用PERL和Win32::OLE在命令行上操作Word文档,但不能从BuildForge步骤操作
EN

Stack Overflow用户
提问于 2016-07-23 04:18:38
回答 1查看 307关注 0票数 0

我有功能的PERL脚本,用于更新Word文档。PERL脚本编码为可与MS Office 2003或2007一起使用。我尝试通过BF进行更新的计算机上安装了Office 2003,安装了适当的模板,宏安全性设置也已更新。

当我在命令行上运行我希望BF使用的确切命令时,它可以正常工作。当我通过BF步骤运行它时,我得到“* Unable to open doc at Perl line 94”(行号是\servername\projectname\bin\updateVer.pl脚本中的croak )。

脚本看起来就像这样:

代码语言:javascript
复制
# enable Sanity checking and make the variable names meaningful
use strict;
use warnings;
use English;
use Win32::OLE;

# Gain access to MS Word 'wd' constants
use Win32::OLE::Const ('Microsoft Word');

use FindBin qw($RealDir);

use lib ($RealDir, "$RealDir/..", "$RealDir/../lib");

# include the common and log utilities
use SCCM::Common;
use SCCM::Logs;

# use command line inputs
use Getopt::Long qw(:config auto_abbrev permute ignore_case pass_through);

# set up logs and process logfile options
logOptions(qw(-log now));

my  $bookmark_update_result = "";
my  $update_ref_result = "";

# Get input from user

my  $path;
my  $bookmarkName;
my  $bookmarkValue;
my  $Word;
my  $newWord = 0;

GetOptions("path=s"           => \$path,
       "bookmarkName=s"   => \$bookmarkName,
   "bookmarkValue=s"  => \$bookmarkValue);

unless ( defined($path) ) 
   { croakf "%[Fail] Path and filename of SVD are required\n"; }

unless ( defined($bookmarkName) && defined($bookmarkValue) ) 
   { croakf "%[Fail] bookmarkName and bookmarkValue parameters are both required.\n"; }

# Start Word in a safer way, checking to see if user has it open first.

eval
{
  $Word = Win32::OLE->GetActiveObject('Word.Application');
  if (! $Word)
  {
    $newWord = 1;
    $Word = Win32::OLE->new('Word.Application', 'Quit');
  }
};

croakf "%[Fail] -- unable to start Word Engine: $@\n", Win32::OLE->LastError() if ($@ || ! $Word);

my $dispAlerts = $Word->{'DisplayAlerts'};
$Word->{'DisplayAlerts'} = wdAlertsNone;

if ($newWord)
{
  $Word->{'Visible'} = 0;
}

my $doc = $Word->Documents->Open($path) or
   croakf ("%[Fail] Unable to open doc ", Win32::OLE->LastError() );

脚本的调用方式如下:"C:\BuildForgeBuilds\BFProjectName\BFProjectName_0177\MyDocument.doc“\servername\projectname\bin\updateVer.pl -path ccperl -bookmarkValue My_Baseline_10.20.30

我可以得到一些指示来说服BF可以打开我的工作文档吗?谢谢!

EN

回答 1

Stack Overflow用户

发布于 2016-07-26 02:41:03

原来,在我从运行作业的机器上的模板中删除了'Archive‘位之后,BF能够成功地运行它的作业。

有趣的是,我可以直接在服务器上运行它,并在模板上设置了'Archive‘位。但是,嘿,我不再被困在这个问题上了。

感谢任何读过我的问题的人,甚至是考虑过问题的人。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38534668

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档