[英]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.