Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
I wanted to add a note on PowerPoint, as when I googled for "powerpoint Win32::OLE tutorial" this node was the very top link!

So here is how I've gone about creating a PowerPoint presentation.

First load the modules:

use Win32::OLE; use Win32::OLE::Const 'Microsoft Office'; use Win32::OLE::Const 'Microsoft PowerPoint'; use strict;
..then setting warnings as per the Excel tutorial..
$Win32::OLE::Warn = 3; # die on errors

Next, name the file that will be saved:

my $filename = "c:\\temp\\testpower.ppt";
.. and then fire up the PowerPoint application
print( "Starting Powerpoint Object\n" ); my $power = Win32::OLE->GetActiveObject('Powerpoint.Application') || Win32::OLE->new('Powerpoint.Application', 'Quit');

Create a presentation (much like creating a workbook in Excel)

print( "Creating a presentation\n" ); my $ppt = $power->Presentations->Add(); $ppt->SaveAs($filename);
(and save!).

Create a slide (like creating a worksheet in Excel)

print( "Creating a slide\n" ); my $slide = $ppt->Slides->Add(1, ppLayoutBlank); $ppt->SaveAs($filename);

Insert a picture into my slide

my $pname = 'C:\WINNT\Web\Wallpaper\Fall Memories.jpg'; my $shape = $slide->Shapes->AddPicture( $pname, msoFalse, msoTrue, 20, 1 ); # scale to 50% of original size $shape->ScaleHeight( 0.5, msoTrue, msoScaleFromTopLeft ); $shape->ScaleWidth( 0.5, msoTrue, msoScaleFromTopLeft ); $ppt->SaveAs($filename);

Insert a table

print( "Adding a 4 wide by 3 high table\n" ); my $table = $slide->Shapes->AddTable( 3, 4, 1, 100 ); my $columns = $table->Table->Columns->Count; my $rows = $table->Table->Rows->Count; for ( my $row = 0; $row < $rows; $row++ ) { for ( my $col = 0; $col < $columns; $col++ ) { my $cell = $table->Table->Rows($row+1)->Cells($col+1); my $textframe = $cell->Shape->TextFrame; $textframe->TextRange->{Text} = "$col,$row"; $textframe->TextRange->Font->{Bold} = msoFalse; $textframe->TextRange->Font->{Name} = "Arial"; # set text size AFTER changing text $textframe->TextRange->Font->{Size} = "12"; } } $ppt->SaveAs($filename);

There's a lot more that can be done, of course, and the best reference is at MSDN's Visual Basic Reference for PowerPoint. All the methods and properties used here are listed there. In addition, when calling a method, you often can leave parameters off the end and defaults will be used for you.

Another note to add.. if you're not running PowerPoint at the time this script is run, then it will happen in the background. The only way to know for sure if it worked is to open the file you created and visually verify everything was added.


In reply to Re: Using Win32::OLE and Excel - Tips and Tricks by monarch
in thread Using Win32::OLE and Excel - Tips and Tricks by cacharbe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (6)
    As of 2014-12-20 12:18 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (95 votes), past polls