2017-02-10 48 views
0

安裝MS PowerPoint播放器後,我運行下面嘗試加載PowerPoint文件,但未能

unit Unit1; 

interface 

uses  Comobj, 
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
    Dialogs, StdCtrls, ExtCtrls,Office_TLB, office97, PowerPointXP;//, ExtCtrls; 

type 
    TForm1 = class(TForm) 
    Button1: TButton; 
    Panel1: TPanel; 
    procedure Button1Click(Sender: TObject); 
    private 
    { Private declarations } 
    public 
    { Public declarations } 
    end; 

var 
    Form1: TForm1; 

implementation 

{$R *.dfm} 

procedure TForm1.Button1Click(Sender: TObject); 
const 
    ppShowTypeSpeaker = 1; 
    ppShowTypeInWindow = 1000; 
    SHOW_FILE = 'C:\Users\myname\Downloads\practicepowerpoint.ppt'; 
var 
    oPPTApp: OleVariant; 
    oPPTPres: OleVariant; 

    screenClasshWnd: HWND; 
    pWidth, pHeight: Integer; 

    function PixelsToPoints(Val: Integer; Vert: Boolean): Integer; 
    begin 
    if Vert then 
     Result := Trunc(Val * 0.75) 
    else 
     Result := Trunc(Val * 0.75); 
    end; 

begin 
    try 
    oPPTApp := CreateOleObject('PowerPoint.Application'); 
    except 
    showmessage('no ppt');; 
    exit; 
    end; 
    oPPTPres := oPPTApp.Presentations.Open(SHOW_FILE, True, True, False); 
    pWidth := PixelsToPoints(Panel1.Width, False); 
    pHeight := PixelsToPoints(Panel1.Height, True); 
    oPPTPres.SlideShowSettings.ShowType := ppShowTypeSpeaker; 
    oPPTPres.SlideShowSettings.Run.Width := pWidth; 
    oPPTPres.SlideShowSettings.Run.Height := pHeight; 
    screenClasshWnd := FindWindow('screenClass', nil); 
    Windows.SetParent(screenClasshWnd, Panel1.Handle); 

end; 

end. 

的代碼行

oPPTApp := CreateOleObject('PowerPoint.Application'); 

原因的錯誤。

只是想知道我必須安裝PowerPoint播放,而不是PowerPoint播放器之前運行代碼

您的評論歡迎

+0

像這樣的父母方法不起作用。找到一種不同的方式。 –

回答

0

是,「Powerpoint.Application」開始簡報。我不會推薦使用Powerpoint查看器,因爲它是一個非常老的程序(從2010年和之前)。如果您可以自動執行此程序,我不確定。 查看pptx的新方法是Powerpoint online