IB2017 has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to add two elements to an existing PowerPoint if a specific term (in my example "transformation" is found: 1) a text object and with a red background (no transparency) and 2) a note/comment. I manage to do 1) but can't find the option to set the background but I fail completely on point 2). Any suggestion?

#!perl use strict; use warnings; use utf8; use Cwd; use Win32::OLE; use Win32::OLE 'CP_UTF8'; use Win32::OLE::Const 'Microsoft PowerPoint'; $Win32::OLE::Warn = 3; $Win32::OLE::CP = CP_UTF8; my $file = "original.pptx"; my $dir = getcwd(); my $filename = $dir . '\\' . $file; print ("Starting PowerPoint\n"); my $process = Win32::OLE->GetActiveObject('Powerpoint.Application') || Win32::OLE->new('Powerpoint.Application', 'Quit'); print ( "Opening '$filename'\n" ); my $ppt = $process->Presentations->Open($filename); $file =~ s/original/TCF6203/; $filename = "$dir/$file"; my @activeslides = $process->ActivePresentation->Slides->in; foreach my $slide (@activeslides) { my $name = $slide->{Name}; foreach my $shape ($slide->Shapes->in){ if ($shape->TextFrame->HasText){ #TO DO: to get all elements I sho +uld create a loop here if ($shape->HasTextFrame){ my $text = $shape->TextFrame->TextRange->Text; print "$name\nText $text = "; if ($text =~ /transformation/){ my $TextBox=$slide->Shapes->AddTextbox({Orientation=>1, Left=>5, Top=>5, Width=>250, Height=>250, }); $TextBox->TextFrame->TextRange->{Text} ="Big Ole Test"; #$slide->NotesPage->TextRange->{Text} ="Big Ole Test"; #CO +MMENT OUT TO TRY TO ADD NOTE/COMMENT print "OK\n"; } else { print "NOTHING TO DO\n"; }; } } } } print ( "Saving '$filename'\n" ); $ppt->SaveAs($filename);

Replies are listed 'Best First'.
Re: Add comment to PowerPoint Win32::OLE
by poj (Abbot) on Nov 22, 2019 at 16:39 UTC

    To set background

    my $TextBox = $slide->Shapes->AddTextbox({ Orientation => 1, Left => 5, Top => 5, Width => 250, Height => 250 }); $TextBox->TextFrame->TextRange->{Text} ="Big Ole Test"; $TextBox->{'Fill'}{'BackColor'}{'RGB'} = 255; # 0000ff BlueGreenRed; $TextBox->{'Fill'}->Solid;

    If the slide has a notes page

    if ($slide->{HasNotesPage}){ my $ph = $slide->{NotesPage}{Shapes}{Placeholders}; if ($ph->{Count} >= 2){ $ph->item(2)->{TextFrame}{TextRange}{Text} = "New Comment adde +d\nline2\nline3"; print "Note added\n"; } else { print "Error - no placeholder for comment" } } else { print "No notes page\n"; } }

    If a notes page does not exist then sorry I can't help further. See object model

    poj
Re: Add comment to PowerPoint Win32::OLE
by Anonymous Monk on Nov 22, 2019 at 02:46 UTC