proton-69 has asked for the wisdom of the Perl Monks concerning the following question:

Hi PerlMonks, I have found this site very useful. I am trying to automate the power point using Win32::PowerPoint. I have written the following code, but it is giving problems. Code is:
use Win32::PowerPoint; # Global var(s) my $file = "E:\\rameshwar\\dedupe\\test_presentation.pptx"; # create construtor for ppt App and if script dies #un-expectedly then + quit the App my $ppt_ref = Win32::PowerPoint->new || die("Opps, failed to open PPT + App", Win32::OLE::LastError()); # Make it visible by setting property Visible to 1:: if set 0 it is in +visible $ppt_ref->{Visible} = 1; # set presentation-wide information $ppt_ref->new_presentation( background_forecolor => [255,255,255], background_backcolor => 'RGB(0, 0, 0)', pattern => 'Shingle', ); # and master footer if you prefer (optional) $ppt_ref->set_master_footer( visible => 1, text => 'My Slides', slide_number => 1, datetime => 1, datetime_format => 'MMMMyy', ); # do whatever you want to do for each of your slides my @slides; for my $slide (@slides) { # my $slide = $ppt_ref->new_slide; $ppt_ref->add_text($slide->title, { size => 40, bold => 1 }); $ppt_ref->add_text($slide->body_text); $ppt_ref->add_text($slide->link, { link => $slide->link }); } $ppt_ref->save_presentation($file); $ppt_ref->close_presentation;
In the for loop above what are the values for @slides, how that array is populated? I thought it if obj reference to $ppt_ref->new_slide my $slide = $ppt_ref->new_slide; But looks like it is not the case. Please guide me on this. Thanks. Proton-69

Replies are listed 'Best First'.
Re: Win32::PowerPoint to create slides
by Corion (Patriarch) on Jan 12, 2009 at 14:43 UTC

    From looking at the source code of Win32::PowerPoint, the ->new_slide method doesn't return any useful information. The newly allocated slide is stored in $self->{slide}, so you should be able to access it there. It seems that Win32::PowerPoint relies on the idea of having only one "current" slide on which all its methods operate, so that won't buy you much.

    The @slides array in your code is to be populated by yourself. Somewhere, you need to have your own idea of what should go into the slides.

      To supplement Corion's thought on the @slides array, I think the module author assumes that you might create your own Perl data structure.

      Instead of your "for" loop, just try to create a single slide with some dummy information:

      $ppt_ref->add_text('Here is my title'); $ppt_ref->add_text('This is the 1st line of my text'); $ppt_ref->add_text('This is the 2nd line of my text');
Re: Win32::PowerPoint to create slides
by mikelieman (Friar) on Jan 12, 2009 at 14:45 UTC
    Any reason you don't have:

    use strict;
    use warnings;

      I do use that.
A reply falls below the community's threshold of quality. You may see it by logging in.