in reply to Re: Win32::OLE Powerpoint HTML
in thread Win32::OLE Powerpoint HTML
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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Win32::OLE Powerpoint HTML
by ewittry (Initiate) on Jul 08, 2008 at 17:18 UTC |