我正在尝试从Word 文档中的多个表中提取数据。尝试将表中的数据转换为文本时出现错误。ConvertToText方法有两个可选参数(如何分隔数据和一个布尔值)。这是我当前的代码:
#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 qw(in);
use Win32::OLE::Const 'Microsoft Word';
use Win32::OLE::Variant;
my $var1 = Win32::OLE::Variant->new(VT_BOOL, 'true');
$Win32::OLE::Warn = 3;
#set the file to be opened
my $file = 'C:\work\SCL_International Financial New Fund Setup Questionnaire V1.6.docx';
#Create a new instance of Win32::OLE for the Word application, die if could not open the application
my $MSWord = Win32::OLE->GetActiveObject('Excel.Application') or Win32::OLE->new('Word.Application','Quit');
#Set the screen to Visible, so that you can see what is going on
$MSWord->{'Visible'} = 1;
$MSWord->{'DisplayAlerts'} = 0; #Supress Alerts, such as 'Save As....'
#open the request file or die and print warning message
my $Doc = $MSWord->{'Documents'}->Open($file) or die "Could not open ", $file, " Error:", Win32::OLE->LastError();
#$MSWord->ActiveDocument->SaveAs({Filename => 'AlteredTest.docx',
#FileFormat => wdFormatDocument});
my $tables = $MSWord->ActiveDocument->{'Tables'};
for my $table (in $tables){
my $tableText = $table->ConverToText(wdSeparateByParagraphs,$var1);
print "Table: ", $tableText, "\n";
}
$MSWord->ActiveDocument->Close;
$MSWord->Quit;
我收到了这个错误:
在 OLEWord.pl 第 31 行使用“strict subs”时不允许裸词“VT_BOOL” 在 OLEWord.pl 第 31 行使用“strict subs”时
不允许裸词“true”
由于编译错误而中止 OLEWord.pl 的执行。