尝试加载PowerPoint文件,但未能

问题描述:

安装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

像这样的父母方法不起作用。找到一种不同的方式。 –

是,“Powerpoint.Application”开始简报。我不会推荐使用Powerpoint查看器,因为它是一个非常老的程序(从2010年和之前)。如果您可以自动执行此程序,我不确定。 查看pptx的新方法是Powerpoint online