尝试加载 powerpoint 文件但失败

try to load powerpoint file but failed

安装 MS Powerpoint Viewer 后,我运行下面的代码

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 Viewer

欢迎您的评论

是,"Powerpoint.Application" 启动 Powerpoint。我不建议使用 powerpoint 查看器,因为它是一个非常古老的程序(2010 年及之前)。我不确定你是否可以自动化这个程序。 新的pptx查看方式是Powerpoint online