另請參閱我對Automating a Job at Work: Importing Powerpoint Bullet Text into an Excel Sheet的回答。
PowerPoint幻燈片沒有特定的Title
屬性。他們有一個Name
財產,但這不是一回事。形狀的佔位符類型屬性可以告訴你,如果它是一個標題:
#!/usr/bin/perl
use strict; use warnings;
use Try::Tiny;
use Win32::OLE;
use Win32::OLE::Const qw(Microsoft.PowerPoint);
use Win32::OLE::Enum;
$Win32::OLE::Warn = 3;
my $ppt = get_ppt();
my $presentation = $ppt->Presentations->Open('test.ppt', 1);
my $slides = Win32::OLE::Enum->new($presentation->Slides);
SLIDE:
while (my $slide = $slides->Next) {
printf "%s:\t", $slide->Name;
my $shapes = Win32::OLE::Enum->new($slide->Shapes);
SHAPE:
while (my $shape = $shapes->Next) {
my $type = $shape->PlaceholderFormat->Type;
if ($type == ppPlaceholderTitle
or $type == ppPlaceholderCenterTitle
or $type == ppPlaceholderVerticalTitle
) {
print $shape->TextFrame->TextRange->text;
last SHAPE;
}
}
print "\n";
}
$presentation->Close;
sub get_ppt {
my $ppt;
try {
$ppt = Win32::OLE->GetActiveObject('PowerPoint.Application');
}
catch {
die $_;
};
unless ($ppt) {
$ppt = Win32::OLE->new(
'PowerPoint.Application', sub { $_[0]->Quit }
) or die sprintf(
'Cannot start PowerPoint: %s', Win32::OLE->LastError
);
}
return $ppt;
}
輸出:
Slide1: Title Page Title
Slide2: Page with bullets
Slide3: Page with chart
Slide4:
顯然,這是在Slide4沒有標題。
是的,這給了我一些有用的提示。奇怪的是它沒有出現在我的搜索嘗試中。謝謝 – justintime 2010-09-09 17:34:22
只有預防我的事情是我沒有看到它的事實:-)。昨天晚上忙於工作,白天工作。 – justintime 2010-09-10 20:05:42
@justintime好的,謝謝。 – 2010-09-10 20:18:42