我試圖在Word文檔中從多個表中提取數據。當試圖將表中的數據轉換爲文本時,我得到一個錯誤。該ConvertToText方法有兩個可選參數(如何單獨的數據,和一個布爾值)。這裏是我當前的代碼:從Word中的表中提取原始數據?使用Perl
#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;
,我得到這個錯誤:
Bareword "VT_BOOL" not allowed while "strict subs" in use at OLEWord.pl line 31
Bareword "true" not allowed while "strict subs" in use at OLEWord.pl line 31
Execution of OLEWord.pl aborted due to compilation errors.
是的,我忘了那個謝謝,但是如何從Word> – Shahab
@Shahab表格中提取數據 - 請參閱我的表格提取代碼的更新答案。 – bvr
嗯,我得到一個錯誤正在運行:從「Microsoft Word」OLE異常此方法或屬性不可用,因爲部分或全部數據不參考表 - >在ConverToText。 – Shahab