Perl win32:OLE对Word的调用不适用于visible=0,通过SSHD的远程脚本
使用运行在Windows服务器上的ssh到WinSSHD远程访问Windows 2008 R2/perl 5.14.1 x64/Word 2010管理员帐户。此perl脚本在(本地、管理)命令行中运行良好:Perl win32:OLE对Word的调用不适用于visible=0,通过SSHD的远程脚本,perl,ssh,ole,win32ole,Perl,Ssh,Ole,Win32ole,使用运行在Windows服务器上的ssh到WinSSHD远程访问Windows 2008 R2/perl 5.14.1 x64/Word 2010管理员帐户。此perl脚本在(本地、管理)命令行中运行良好: use warnings; use strict; use Win32::OLE; use Win32::OLE::Const 'Microsoft.Word'; # wd constants use Win32::OLE::Const 'Microsoft Office 14.0
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咒语来创建word应用程序对象,但我不知道如何将其转换为win32::OLE可以接受的内容,即。
Microsoft.Office.Interop.Word.ApplicationClass createobject(“Word.Application”)
(我无法找到具体的建议,但它不是perlish)
感谢您的帮助有一点是
FileName=>“exampletext.doc”
-这不是一个绝对路径。。。也许它是想在不允许或空间不足的地方节省空间
这可能与这一点有关:WinSSHD是否作为服务运行?
如果是,则根据MS不支持办公自动化-请参见一点是
FileName=>“exampletext.doc”
-这不是绝对路径。。。也许它是想在不允许或空间不足的地方节省空间
这可能与这一点有关:WinSSHD是否作为服务运行?
如果是,则MS不支持办公自动化-请参阅