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

Hi Monks, I have to create a column chart with rwo series in a ppt, I have the data for the chart in separate arrays. Please help me withthe command to add a chart in a ppt. I have give the code that i used to create a ppt and add a slide in it.

my $PptApp = Win32::OLE->GetActiveObject('PowerPoint.Application')|| +Win32::OLE->new('PowerPoint.Application', 'Quit'); $PptApp->{Visible} = 1; #my $Presentation = $PptApp->Presentations->Add(); my $Presentation = $PptApp->Presentations->Open({FileName=>'C:\Users\n +1013784\Desktop\New folder\weeklytemplate1.pptx',ReadOnly=>0}); my $value = 0; my $AfterSlide = "Agenda"; my $SlideIndex = 1; my $slides = Win32::OLE::Enum->new( $Presentation->Slides ); while ( my $slide = $slides->Next ) { print "Slide_Name : " . $slide->Name . "\n"; my $shapes = Win32::OLE::Enum->new( $slide->Shapes ); SHAPE: while ( my $shape = $shapes->Next ) { my $type = $shape->PlaceholderFormat->Type; if ( $type == ppPlaceholderTitle or $type == ppPlaceholderCent +erTitle or $type == ppPlaceholderVerticalTitle) { print "Title : |" . $shape->TextFrame->TextRange->text . " +|\n"; if($shape->TextFrame->TextRange->text eq $AfterSlide){ $value = $SlideIndex + 1; print "Put it on $SlideIndex\n"; } $SlideIndex++; last SHAPE; } } print "\n"; } my $Slide = $Presentation->Slides->Add({Index=>$value , Layout=>ppLayo +utText}); $Slide->{Name} = "111 + $dev"; my $Title=$Slide->Shapes->{Title}; $Title->TextFrame->TextRange->{Text} ="Weekly Metrics - Closed Tick +ets";

Replies are listed 'Best First'.
Re: Create a chart in PPT
by hdb (Monsignor) on Mar 21, 2013 at 09:00 UTC
    Hi arundurai, have a look at http://support.microsoft.com/kb/222687 which gives you the VBA equivalent. Translating into perl is straightforward, mainly replacing . by ->. Hope this is helpful.

      I don't know VBA, I looked at that link and could not understand it:-(, If you can please say the command to create a chart and provide data to that chart. Thank you

        Oddly enough, nobody knows VBA from birth, you have to learn it, like most other things. The link I provided you with gives a short example of VBA to Perl/Win32::OLE conversion.

        Let me help you to get started. But I am afraid if you want to program MS Office using Perl, you have to learn this...

        my $chart = $Slide->Shapes->AddOLEObject( 50, 50, 500, 500, "MSGraph.C +hart" ); my $graph = $chart->OLEFormat->Object; my $datasheet = $graph->Application->DataSheet; explore( $datasheet ); $datasheet->Cells(1,2)->{'Value'} = "Col1"; $datasheet->Cells(1,3)->{'Value'} = "Col2"; $datasheet->Cells(1,4)->{'Value'} = "Col3"; $datasheet->Cells(1,5)->{'Value'} = "Col4"; $datasheet->Cells(2,1)->{'Value'} = "Row1"; $datasheet->Cells(3,1)->{'Value'} = "Row2"; $datasheet->Cells(4,1)->{'Value'} = "Row3"; $datasheet->Cells(5,1)->{'Value'} = "Row4"; for( my $row=2; $row<=5; $row++ ) { for( my $col=2; $col<=5; $col++ ) { $datasheet->Cells($row,$col)->{'Value'} = rand(); } } $datasheet->Application->Update;

        Right now I have not time to exhaustively test this so you need to play with it as described in my earlier post.

Re: Create a chart in PPT
by Corion (Patriarch) on Mar 21, 2013 at 10:12 UTC
      The later versions of Powerpoint (I think starting from 2007) do not have a Macro Recorder anymore (victory of the Dark Side, I assume).

        Good point. It seems that the Macro Recorder still exists, but you have to enable it explicitly. At least that's how it works for me, but $work may have fiddled with the "default" settings of Office a bit too much.

        Microsoft Office 2007 still has the macro recorder, in both Excel and PowerPoint. It's just a bit hidden. I don't know about later versions of Office though.

        Update: Sorry, I was wrong. PowerPoint might not have the record macro feature. If it does, I can't activate it.

Re: Create a chart in PPT
by marto (Cardinal) on Mar 21, 2013 at 09:10 UTC

    For automating these applications I suggest you spend time learning about the DOM, using the Macro recorder and converting the VB to Perl Using OLE with Perl.

    Update: Apparently the macro recorder feature was removed after a certain version number of Powerpoint, so your version may not have it. More details on this in the other responses