【问题标题】:win32:OLE calls to Word do not work with visible=0, remote script via SSHDwin32:对 Word 的 OLE 调用不适用于可见 = 0,通过 SSHD 的远程脚本
【发布时间】:2011-07-27 23:46:44
【问题描述】:

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

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”) (我无法找到具体的建议,但它并没有失效)。

感谢您的帮助

【问题讨论】:

    标签: perl ssh ole win32ole


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多