in reply to Re: (cacharbe): Powerpoint OLE
in thread Powerpoint OLE

Hello there monks,
After a couple days of "harsh" work, I finally managed to read text included in powerpoint slides. It may be of use to any of you working with Powerpoint. It also shows how to easily access PPT's properties. So here are the bits and pieces of code. I'll write a snippet with a complete function and program to access Powerpoint some time soon...
package readPowerPoint; use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft PowerPoint'; use Win32::OLE::Const 'Microsoft Office'; use Data::Dumper; require Exporter; use vars qw(@ISA @EXPORT); @ISA = qw(Exporter); @EXPORT = qw(readActivePPT); sub readActivePPT # this method returns the name of the active PPT, its content and a ha +sh # the PPT's properties we consider to be useful. Hence it is ready fo +r use { if ( my $powerpoint = Win32::OLE->GetActiveObject('Powerpoint.Appli +cation')) # connect to powerpoint application { if (defined (my $activePPT=$powerpoint->ActivePresentation)) { my $PPTName = $activePPT->Name; # retrieve PPT name i.e. subj +ect my $PPTProperties = $activePPT->{BuiltInDocumentProperties}; my %PPTContent = (); # read PPT content - see below for struc +ture details for my $slideNumber(1..$activePPT->{Slides}->Count) { my $total = $slideNumber / $activePPT->{Slides}->Count; print "\n---------------- Please wait (".100*$total."% don +e)----------------"; my $slide = $activePPT->slides($slideNumber); if ($slide->{Shapes}->Count) { for my $shapeNumber(1..$slide->{Shapes}->Count) { if ( ($slide->shapes($shapeNumber)->HasTextFrame()== +msoCTrue) or($slide->shapes($shapeNumber)->HasTextFrame()== +msoTrue)) { my $wordGroup=$slide->shapes($shapeNumber)->TextFrame->{T +extRange}; if (defined $wordGroup) { my $text = ""; foreach my $palabre (in $wordGroup->Words) # prints ou +t every single word { $text.= lc($palabre->{Text})." "; # lc stands for l +ower case } $PPTContent{("slide".$slideNumber)}{("shape".$ +shapeNumber)} = $text; } } } } } return ($PPTName,$PPTProperties,%PPTContent); } } return (undef,undef,undef); } # structure of $PPTContent will be a hash of hashes : # first hash will contain all the slides and each slide will be a hash + itself containing all # the text areas found. # to access do this $PPTContent{slide1}{shape1}
Heureux qui, comme Ulysse, a fait un beau voyage
Ou comme celui-là qui conquit la Toison,
Et puis est retourné plein d'usage et raison,
Vivre entre ses parents le reste de son âge!

J. du Bellay, poëte angevin