我是 perl 中 win32:ole 模块的新手。我正在尝试在命令提示符下打印 MS 字表数据行。但我只能打印表格的最后一行。你能帮我解决这个问题吗?提前致谢。
下面是我的代码:
#!/usr/bin/perl 
use strict;
use warnings; 
use File::Spec::Functions qw( catfile );
use Win32::OLE qw(in); 
use Win32::OLE::Const 'Microsoft Word'; 
$Win32::OLE::Warn = 3; 
my $word = get_word(); 
$word->{DisplayAlerts} = wdAlertsNone; 
$word->{Visible} = 1;
my $doc = $word->{Documents}->Open('C:\\PerlScripts\\myTest.docx');
my $tables = $word->ActiveDocument->{'Tables'};
for my $table (in $tables)
{
   my $tableText = $table->ConvertToText({ Separator => wdSeparateByTabs });
   print "Table: ". $tableText->Text(). "\n";
}
$doc->Close(0); 
sub get_word 
{ 
    my $word; 
    eval { $word = Win32::OLE->GetActiveObject('Word.Application');}; 
    die "$@\n" if $@;
    unless(defined $word) 
    { 
       $word = Win32::OLE->new('Word.Application', sub { $_[0]->Quit }) 
       or die "Oops, cannot start Word: ", Win32::OLE->LastError, "\n"; 
    } 
  return $word; 
}