2016-11-17 123 views
0

我想要打開並閱讀PowerPoint演示文稿的幻燈片中的文本。 我該怎麼做? 我知道我可能不得不使用Win32:OLE,但到目前爲止,我試過的所有代碼示例都不起作用。Perl - 打開並閱讀.ppt/.pptx文件?

編輯: 我只有這部分代碼不工作:

$file = "C:\file.pptx"; 
my $powerpoint = Win32::OLE->GetActiveObject('Powerpoint.Application'); 
my $document = $powerpoint->Presentations->Open($file); 
my $slides = Win32::OLE::Enum->new($document->Slides); 
print $slides; 

謝謝!

+0

您能告訴我們您嘗試過什麼嗎? – Schwern

+0

是的,我編輯了我的帖子 – gambit20088

+1

你試圖運行這個代碼的平臺是什麼?示例中的代碼僅適用於安裝了PowerPoint的Windows系統。 – duskwuff

回答

1

我有一個簡短的例子,它演示extracting bullet lists

你的具體問題是由於

$file = "C:\file.pptx"; 

在右手邊,你有一個包含\f一個雙引號字符串。 \f代表form feed。也就是說,該字符串包含C,:,FF,i,le

您可以使用$file = "C:\\file.pptx"獲取驅動器C:的根目錄中file.pptx的實際路徑。

+0

現在,我收到一個錯誤消息: 'Can not call method「Presentations」on C:\ program.pl line 13.'',這在我的代碼中是第三行。 – gambit20088

0

你可以嘗試這樣的事情嗎?還要驗證文件是否可訪問?嘗試將文件放在腳本所在的同一目錄中,然後確保通過刪除路徑來指向它。此外,請確保該Powerpoint文件是一個有效的Powerpoint文件,並可以使用Powerpoint安裝打開。

use Win32::OLE qw(in with); 
use Win32::OLE::Const 'Microsoft PowerPoint'; 

my $powerpoint = Win32::OLE->GetActiveObject('Powerpoint.Application') or die "Unable to open"; 
my $document = $powerpoint->Presentations->Open({FileName=>'c:\\file.pptx', ReadOnly=>1}); 
...do stuff from here...