Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Adding Slide to Powerpoint

by ~~David~~ (Hermit)
on Feb 16, 2007 at 20:57 UTC ( #600522=perlquestion: print w/replies, xml ) Need Help??
~~David~~ has asked for the wisdom of the Perl Monks concerning the following question:

Sorry folks, I really have no idea what I am doing here, but this is my goal. I am building a powerpoint presentation that will be a compilation of various presentations. Right now I am having trouble adding the slides from the second file to the first file. The following code returns this error: Win32::OLE(0.1502) error 0x80048240 in METHOD/PROPERTYGET "Slides" at line 256 Can't modify non-lvalue subroutine call at line 259.
sub addMyFile{ my $file = shift; #this is the filename of the file i am adding my $fullpath = "$edmdir\\$file"; #full filename with path my $pptadd = Win32::OLE->new( 'PowerPoint.Application', 'Quit' )or + die "Can't create PowerPoint OLE: $!\n"; $pptadd->{Visible} = 1; my $addpres = $pptadd->Presentations->Open( $fullpath ) or die "Ca +n't open PowerPoint file '$fullpath': $!\n"; # this is the second pr +esentation.... i need to add it to the first one which has variable +$pres my @slides; my $j = 1; my $slide; while ($addpres->Slides($j)){$slides[$j] = $addpres->Slides($j);$j +++}; #this goes one too many, but I am working on it. my $k = 1; foreach $slide (@slides){ $pres -> Slides($slideIndex) = $slides[$ +k]; $slideIndex++; $k++}; }
Any help would be greatly appreciated. Thanks,

Replies are listed 'Best First'.
Re: Adding Slide to Powerpoint
by traveler (Parson) on Feb 16, 2007 at 22:10 UTC
    foreach $slide (@slides){ $pres -> Slides($slideIndex) = $slides[$k]; +$slideIndex++; $k++};
    Needs to be
    foreach $slide (@slides){ $pres -> Slides->Add($slideIndex,$slides[$k] +->Layout) = $slides[$k]; $slideIndex++; $k++};
    Untested, but it is close to an existing proggie I have.


      Thanks for your suggestions, but I am still having problems. I see what you were trying to accomplish, so it has given me a better starting point. I updated the code, but it still fails with the same error. Do you know if I need to switch between active presentations in order to copy, paste, etc...
      sub addMyFile{ my $file = shift; my $fullpath = "$edmdir\\$file"; my $addpres = $ppt->Presentations->Open( $fullpath ) or die "Can't + open PowerPoint file '$fullpath': $!\n"; my $j = 1; my $slide; my $newslide; while ($j < 10){ # this is hard coded while i figure out the bug +s, but it will be length of the file $newslide = $pres -> Slides->Add($slideIndex,$addpres->Slides( +$j)->Layout); $newslide = $addpres->Slides($j); $j++; $slideIndex++; } };
        You do not need to switch presentations: using the proper var does that. Your old logic (with my changes) was better. Exactly what line gave the error on my version? Oh, and print out $k and $slideindex to be sure they are right and to figure when the error occurs.
      Everyone, Thanks for your help. For reference, here is the working code...
      sub addMyFile{ my $file = shift; #this is the filename of the file i am adding my $fullpath = "$edmdir\\$file"; #full filename with path my $addpres = $ppt->Presentations->Open( $fullpath ) or die "Can't + open PowerPoint file '$fullpath': $!\n"; my @slides; my $j = 1; my $slide; while ($addpres->Slides($j)){$slides[$j] = $addpres->Slides($j);$j +++}; shift(@slides); #because I start at 1, i need to drop off the fir +st element. my $m; my $k = 0; foreach (@slides){ $m = $k+1; #because slide index starts at 1, not 0; $addpres->Slides($m)->Copy; #copy newly opened file slide... $pres->Slides->Paste($slideIndex); #past it into current pres +entation. $slideIndex++; $k++; } }
Re: Adding Slide to Powerpoint
by Herkum (Parson) on Feb 17, 2007 at 00:25 UTC

    The error you were getting was, Can't modify non-lvalue subroutine at line 259. Your problem point was this,

    $pres -> Slides($slideIndex) = $slides[$k];

    Generally, in Perl, you cannot do an assignment of a value to a function/method. A lvalue assignment would like like this,

    $foo->bar() = 'my value';

    I know that traveler solved your problem but maybe this will help you when you try and debug the next issue...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://600522]
Approved by Tanktalus
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2018-03-19 13:07 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (240 votes). Check out past polls.