2016-11-17 121 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...