1

使用 ssh 远程访问 Windows 2008 R2 / perl 5.14.1 x64 /Word 2010 管理员帐户到 Windows Server 上运行的 WinSSHD。这个 perl 脚本从(本地,管理员)命令行运行良好:

use warnings;
use strict;
use Win32::OLE;
use Win32::OLE::Const 'Microsoft.Word';    # wd  constants
use Win32::OLE::Const 'Microsoft Office 14.0 Object Library';  # mso constants
use Win32::OLE qw( in with );
my $word = CreateObject Win32::OLE 'Word.Application' or die $!;
$word->{'Visible'} = 0; # note, for debugging only; otherwise use 0
print ">> Creating a new document\n";
my $document = $word->Documents->Add;
with(   $document->{BuiltinDocumentProperties},
Title => "OLE Word Perl",
Author => "Car Friedberg",
Subject => "simple example" );
print ">> Creating a selection at insertion point\n";
# selection is the insertion point.
my $selection = $word->Selection;

print ">> Insert text \n";
$selection->TypeText("This is a test.");
$selection->TypeParagraph;
$selection->TypeText( "End of test.");

print ">> Save document \n";
# save the document (works with Word 2010) (could use wdFormatPDF or wdFormatRTF)
$word->ActiveDocument->SaveAs({
FileName => 'exampletext.doc',
FileFormat =>  wdFormatDocument,
LockComments => msoFalse,
Password => "", 
AddToRecentFiles =>  msoFalse,
    WritePassword => "", 
    ReadOnlyRecommended => msoFalse, 
    EmbedTrueTypeFonts =>  msoFalse, 
    SaveNativePictureFormat => msoFalse, 
    SaveFormsData => msoFalse,
    SaveAsAOCELetter => msoFalse});

$word->ActiveDocument->Close(wdDoNotSaveChanges);
$word->Quit();`

远程 shell 输出如下所示:

C:\Users\Administrator>perl -w \winbat\ole_example.pl
>> Creating a new document
>> Creating a selection at insertion point
>> Insert text >> Save document
OLE exception from "Microsoft Word":Command failedWin32::OLE(0.1709) error 0x800a1066
in METHOD/PROPERTYGET "SaveAs" at \winbat\ole_example.pl line 34

有什么提示吗?我认为问题与使用单词 {visible}=0 属性有关,该属性必须设置为远程运行。我发现一篇帖子建议使用完整的 Microsoft Office 咒语来创建单词应用程序对象,但我不知道如何将其转换为 win32::OLE 可以接受的内容,即 Microsoft.Office.Interop.Word.ApplicationClass createobject ( “Word.Application”)(我无法找到具体的建议,但它并没有失效)。

谢谢你的帮助

4

1 回答 1

1

一点是FileName => 'exampletext.doc'-这不是绝对路径...也许它正在尝试保存不允许或空间不足的地方...

这可能与这一点有关:
WinSSHD 是否作为服务运行?
如果是,则 MS 不支持办公自动化 - 请参阅http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2

于 2011-07-28T00:00:06.590 回答