Я пытаюсь открыть текстовый документ и просто извлекаю весь текст, который есть в документе, и показываю его пользователю, используя Win32 :: OLE
#usr/bin/perl
#OLEWord.pl
#Use string and print warnings
use strict;use warnings;
#Using OLE + OLE constants for Variants and OLE enumeration for Enumerations
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Word';
$Win32::OLE::Warn = 3;
#set the file to be opened
my $file = '/work/Test.docx';
#Create a new instance of Win32::OLE for the Word application, die if could not open the application
my $MSWord = Win32::OLE->new('Word.Application','Quit') and "Opened Word" or die "Unable to open document ", Win32::OLE->LastError();
#Set the screen to Visible, so that you can see what is going on
$MSWord->{'Visible'} = 1;
#open the request file or die and print warning message
my $Doc = $MSWord->Documents->Open('C:\work\Test.docx') or die "Could not open ", $file, " Error:", Win32::OLE->LastError();
#$MSWord->ActiveDocument->SaveAs({Filename => 'AlteredTest.docx',
#FileFormat => wdFormatDocument});
sub ShowObjs {
my $obj = shift;
foreach (sort keys %$obj) {
print "Keys: $_ - $obj->{$_}\n"; }
}
my $paragraphs = $Doc->Paragraphs;
ShowObjs($paragraphs);
# Get and print the Text inside the opened file
my $paragraphs = $Doc->Paragraphs;
my $txt = $Doc->Range->Text;
print $txt;
$MSWord->ActiveDocument->Close;
$MSWord->Quit;
Я получаю этот код ошибки:
Исключение OLE из Microsoft Word:
Команда не выполнена
Win32 :: OLE (0.1709) ошибка ox800a1066 в МЕТОД / PROPERTYGET Открыть в OLEWord.pl строке 20
Обновление: я могу открыть приложение Word нормально, проблема возникает только тогда, когда я пытаюсь открыть файл.
$txt = $Word->Paragraphs...
). У вас есть разрешение на открытие файла, а файл еще не открыт в Word? - person mrk   schedule 15.07.2011