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

Greetings Wise Ones,

I am tasked with programmatically creating HTML versions of PowerPoint documents (to create what is manually created when one saves as a web page). I have been noodling with Win32::OLE, and have been successful in opening PowerPoint, and opening a test file, but cannot seem to write the HTML output. I have pulled this off for with Word, as there is quite a bit of documentation for Word and Excel, but it is quite scarce for PowerPoint. I can 'SaveAs' back to a PowerPoint document, but not HTML. Does any one have such experience with outputing to HTML? Any help is much appreciated. Thanks.

Gary

Replies are listed 'Best First'.
Re: Win32::OLE Powerpoint HTML
by cacharbe (Curate) on Mar 04, 2002 at 15:32 UTC
    You just need the right constant in your SaveAs Command:
    use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft PowerPoint'; my $filename = 'somehtml.html'; my $PptApp = Win32::OLE->GetActiveObject('PowerPoint.Application') || Win32::OLE->new('PowerPoint.Application', 'Quit'); $PptApp->{Visible} = 1; my $Presentation = $PptApp->Presentations->Open({Filename=>'somepres +entation.ppt', ReadOnly=>1}); $Presentation->SaveAs({Filename => $myfilename, FileFormat=> ppSaveAsHTML});

    C-.

    Update:I should have put some references in- I found the proper constant using the object viewer in Visual Basic (I added a reference to the PowerPoint libs to a proj). If you DON'T have VB installed, and you are using Active State's install, then I would suggest using their web-based object browser. It's a file named, aptly enough, browser.html, and I found mine in -

    c:\perl\html\site\win32\ole\browser

      WOO HOO!!!

      That did it. Thank you.

      Gary

      Update: Apologies for my outburst, but as you can tell cacharbe's response solved a problem that I had been very frustrated with. I couldn't seem to find the ppSaveAsHTML constant anywhere. There doesn't seem to be much around with regards to manipulating PowerPoint documents, so I thought I'd post the code that I eventually came up with. It runs as a CGI, and takes the file name as an argument. It converts Excel, Word or PowerPoint documents to HTML, and also converts PowerPoint slides to JPEG, since Netscape can't view the HTML that PowerPoint creates. A simple script can display these JPEGs. This code would be better if it determined file type from MIME, but that's for another day. Hope this helps someone someday.

      use CGI; use Win32::OLE::Const 'Microsoft Word'; use Win32::OLE::Const 'Microsoft Excel'; use Win32::OLE::Const 'Microsoft PowerPoint'; use strict; my $q = new CGI; my $file_name = $q->param('file'); if ( $file_name eq '' ) { $file_name = $ARGV[0]; } my $in_dir = "C:\\some_dir\\"; my $out_dir = "C:\\some_other_dir\\"; # die on errors... $Win32::OLE::Warn = 3; if ( $file_name =~ m/\.doc$/ ) { convert_word( $file_name, $in_dir, $out_dir ); } elsif ( $file_name =~ m/\.xls$/ ) { convert_excel( $file_name, $in_dir, $out_dir ); } elsif ( $file_name =~ m/\.ppt$/ ) { convert_powerpoint( $file_name, $in_dir, $out_dir ); } exit; ################## sub convert_word { ################## my ( $file_name, $in_dir, $out_dir ) = @_; # get already active Word application or open new or die my $word = ( Win32::OLE->GetActiveObject('Word.Application') || Win32::OLE->new('Word.Application', 'Quit') || print Win32::OLE->LastError ); my $wd_in_filename = $in_dir.$file_name; my $word_doc = $word->Documents->Open($wd_in_filename); my $wd_out_filename = $out_dir.$file_name.".htm"; $word_doc->SaveAs( { FileName => "$wd_out_filename", FileFormat => 8 } ); # File Format 8 = HTML $word_doc->Close(); $word->Quit(); } ################### sub convert_excel { ################### my ( $file_name, $in_dir, $out_dir ) = @_; # get already active Excel application or open new or die my $excel = ( Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit') || print Win32::OLE->LastError ); my $xl_in_filename = $in_dir.$file_name; my $excel_doc = $excel->Workbooks->Open($xl_in_filename) or die "O +pen Failed"; my $excel_sheet = $excel_doc->Worksheets(1); my $xl_out_filename = $out_dir.$file_name.".htm"; unlink $xl_out_filename if -f $xl_out_filename; $excel_sheet->SaveAs( { 'FileName' => $xl_out_filename, 'FileFormat' => xlHtml } ); $excel_doc->Close(); $excel->Quit(); } ######################## sub convert_powerpoint { ######################## my ( $file_name, $in_dir, $out_dir ) = @_; # get already active PowerPoint application or open new or die my $powerpoint = ( Win32::OLE->GetActiveObject('PowerPoint.Applica +tion') || Win32::OLE->new('PowerPoint.Application', 'Quit') || print Win32::OLE->LastError ); my $pp_in_filename = $in_dir.$file_name; $powerpoint->{Visible} = 1; $powerpoint->Activate(); my $powerpoint_doc = $powerpoint->Presentations->Open($pp_in_filen +ame); my $pp_out_html_filename = $out_dir.$file_name.".htm"; my $pp_out_jpg_filename = $out_dir."ns\\".$file_name; ## output J +PEG for Netscape users $powerpoint_doc->SaveAs( { FileName => "$pp_out_html_filename", FileFormat => ppSaveAsHTML } ); $powerpoint_doc->SaveAs( { FileName => "$pp_out_jpg_filename", FileFormat => ppSaveAsJPG } ); $powerpoint_doc->Close(); return; }
        Win32::OLE(0.1702) error 0x80070005: "Access is denied" at C:\InetPub\WWWROOT\cgi-bin\test.cgi line 20 eval {...} called at C:\InetPub\WWWROOT\cgi-bin\test.cgi line 20 How do I have to set the Access?