[英]How to read picture/image from word document using Win32::OLE in perl
使用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()))
{
}
请帮助我也阅读图像/图片。 提前致谢。
为此,您需要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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.