尝试加载powerpoint文件但失败了

时间:2017-02-10 01:18:03

标签: delphi powerpoint

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

您的评论欢迎

1 个答案:

答案 0 :(得分:0)

是的," Powerpoint.Application"启动Powerpoint。我不建议使用powerpoint viewer,因为它是一个非常古老的程序(从2010年开始)。如果你可以自动化这个程序,我不是一侠。 查看pptx的新方法是Powerpoint online