0

使用 Win32::OLE 我可以从 word 文档中读取表格、段落。但是我想从word文档中读取图片/图像,有没有获取图片的功能?

下面是表格和段落阅读的代码。

$Word = Win32::OLE->GetActiveObject('Word.Application') || Win32::OLE->new('Word.Application');
$Word->{'Visible'}     = 0;
$Word->{DisplayAlerts} = 0;

my $document = $Word->Documents->Open($Req_doc_path);

### for tables reading
my $tables = $document->{'Tables'};
for my $table (in $tables){
   my $tableText = $table->ConvertToText({ Separator => wdSeparateByTabs });
   #print "Table: ", $tableText->Text(), "\n";
}

### for paragraphs reading
$paragraphs = $document->paragraphs();
$enumerate = new Win32::OLE::Enum($paragraphs);
while(defined($paragraph = $enumerate->Next()))
{

}

#

请帮助我阅读图像/图片。提前致谢。

4

1 回答 1

0

你需要InlineShapes()并且Shapes为此:

#!/usr/bin/perl

use Modern::Perl;
use Win32::OLE;

my $Word = Win32::OLE->GetActiveObject('Word.Application')
  || Win32::OLE->new('Word.Application');
$Word->{'Visible'} = 0;
$Word->{DisplayAlerts} = 0;

my $document = $Word->Documents->Open("test.docx");

my $shapes = $document->InlineShapes(); #you need to process $document->Shapes() also


my $enumerate = new Win32::OLE::Enum($shapes);
while ( defined( my $shape = $enumerate->Next() ) ) {

    say "Width: ", $shape->Width();
}
于 2013-05-02T09:59:12.007 回答