Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

perl can create Office files from Windows

by Anonymous Monk
on Apr 24, 2003 at 21:28 UTC ( #253011=snippet: print w/replies, xml ) Need Help??
Description: I've found few complete and worthwhile perl programs to generate complicated Office files, Word, Excel, and Powerpoint. I've seen many an answer lead the programmer from trying this. It works. I have extensive Word and Excel programs too large for snippets. I am just now toying in Powerpoint and have already gotten further than any post I have found so I'm adding my two cents. Comments were removed for brevity. I'm not a perl guru and I'm sure there may be other ways to do this.
  use strict ;
  $DOS::Filename = "d:\\Temp\\Perl2PowerPoint.ppt" ;
  use Win32::OLE::Const 'Microsoft PowerPoint';
  use Win32::Process ;                      # Launch a Windows program
  $Win32::OLE::Warn = 2 ;                         # return errors...
  if (-f $DOS::Filename) {
    unlink $DOS::Filename ;
  eval {$MS::PowerPoint = Win32::OLE->GetActiveObject('PowerPoint.Appl
+ication')} ;
  die "PowerPoint not installed" if $@ ;
  unless (defined $MS::PowerPoint) {
    $MS::PowerPoint = Win32::OLE->new('PowerPoint.Application', sub {$
       or die "Oops, cannot start PowerPoint" ;
  $MS::PowerPoint->{'Visible'} = 1 ;       # 0 = do not show it
  $ppt::presentation = $MS::PowerPoint->Presentations->Add() ;
  $ppt::Slide = $ppt::presentation->Slides->Add({Index=>1 , Layout=>pp
  $ppt::Slide->{Name} = "Slide1";
  $ppt::presentation->ApplyTemplate('D:\Program Files\Microsoft Office
+\Templates\Presentation Designs\high voltage.pot') ;
   $ppt::slide = $ppt::presentation->Slides->Add({Index=>2 , Layout=>p
   $ppt::slide->{Name} = "Ken";
        Left=>5, Top=>5, Width=>250,  Height=>250,});
   $slide::textbox->TextFrame->TextRange->{Text} ="Big Ole Test";
   $slide::title->TextFrame->TextRange->{Text} ="Title Test";
   $ppt::slide = $ppt::slide->Duplicate();
   $ppt::slide->{Name} = "Slide2";
   $slide::title->TextFrame->TextRange->{Text} ="Slide Test";
  $ppt::presentation->SaveAs( \$DOS::Filename ) ;
  undef $ppt::presentation ;
  undef $MS::PowerPoint ;
Replies are listed 'Best First'.
Re: perl can create Office files from Windows
by RMGir (Prior) on Apr 25, 2003 at 12:06 UTC
    Nice solution for powerpoint.

    For Excel, though, I'd recommend using SpreadSheet::WriteExcel (by jmcnamara) instead, though. It's much simpler to use, and the system the script runs on doesn't need Excel installed. In fact, it doesn't even need to have Windows installed; I generate spreadsheets from unix systems every day.

    For word files, there are a few different RTF generators available, which also won't require Word to be installed on the system doing the generating. RTF::Document looks a bit simpler to use than RTF::Writer, but I haven't played with either much.

(jeffa) Re: perl can create Office files from Windows
by jeffa (Bishop) on Apr 25, 2003 at 12:42 UTC
    Thanks for the code. :)

    Here are some alternative solutions (for those on other platforms besides Win32):

    • Powerpoint? nahh, just use XML::Handler::AxPoint instead
    • Word documents? Well, i recently had to convert some 70 or so Word documents into HTML on my Linux box. I did some searching and found the wvWare library. I didn't like the HTML that the wvHTML tool produced, but wvText did a very good job of producing text, which i was able to convert to HTML via the shabby but very handy HTML::FromText module.


    (the triplet paradiddle with high-hat)
Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://253011]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2020-10-24 02:42 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (242 votes). Check out past polls.