in reply to Error in Extracting Data from the 1st slide of a ppt

Try this cut down version of your code

#!perl use strict; use warnings; use Win32::OLE; use Win32::OLE::Const 'Microsoft PowerPoint'; use Win32::OLE::Enum; use File::Find; use Cwd; my $ppt = Win32::OLE->new( 'PowerPoint.Application', sub { $_[0]->Quit + } ) or die "Cannot start PowerPoint: ".Win32::OLE->LastError; find(\&wanted, cwd()); sub wanted { return unless (/pptx?$/); scan($File::Find::name); } sub scan { my $file = shift; print "Scanning $file\n"; my $p = $ppt->Presentations->Open($file); my $slides = Win32::OLE::Enum->new( $p->Slides ); my $slide = $slides->Next; my $shapes = Win32::OLE::Enum->new( $slide->Shapes ); while ( my $shape = $shapes->Next ){ my $type = $shape->PlaceholderFormat->Type; if ( $type == ppPlaceholderTitle or $type == ppPlaceholderCenterTitle or $type == ppPlaceholderVerticalTitle){ my $title = $shape->TextFrame->TextRange->text; print "Title is $title\n"; } } }
poj

Replies are listed 'Best First'.
Re^2: Error in Extracting Data from the 1st slide of a ppt
by mehtav (Initiate) on Dec 04, 2015 at 18:03 UTC

    Hi Poj,

    Thanks a lot for your help. This code works great while reading the titles. However, I am also trying to extract the author and the date from the 1st slide. If these values are put in placeholders then the code works fine. However, these are put in a textbox then the line

    " my $type = $shape->Placeholderformat->Type; "

    gives a type mismatch error. I am assuming thats because a textbox does not count as a placeholder. How do I try to fix that?

      Deal with different shape types with if/else statements. (You can use the object browser to inspect the msoShapeType constant values)

      sub scan { my $file = shift; print "Scanning $file\n"; my $p = $ppt->Presentations->Open($file); my $slides = Win32::OLE::Enum->new( $p->Slides ); my $slide = $slides->Next; my $shapes = Win32::OLE::Enum->new( $slide->Shapes ); while ( my $shape = $shapes->Next ){ my $stype = $shape->type; print "Shape type is $stype\n"; if ($stype == 17){ my $text = $shape->TextFrame->TextRange->text; print "TextBox is $text\n"; } elsif ($stype == 14){ my $type = $shape->PlaceholderFormat->Type; if ( $type == ppPlaceholderTitle or $type == ppPlaceholderCenterTitle or $type == ppPlaceholderVerticalTitle ){ my $title = $shape->TextFrame->TextRange->text; print "Title is $title\n"; } } } }
      poj