⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 这是用Delphi获取已安装的office的版本的源码。
💻 PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,ComObj, StdCtrls,MSPpt2000,
  OleServer, OleCtrls, OleCtnrs;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    OpenDialog1: TOpenDialog;
    Button3: TButton;
    Button4: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{
const
  Wordversion97 = 8; 
  Wordversion2000 = 9; 
  WordversionXP = 10; 
  Wordversion2003 = 11; 
} 

function GetInstalledWordVersion: Integer;
var 
  word: OLEVariant; 
begin
  try
    word := CreateOLEObject('Word.Application');
  except
    ShowMessage('Error...');
    Exit;
  end;
  result := word.version; 
  word.Quit; 
  word := UnAssigned; 
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(IntToStr(GetInstalledWordVersion));  
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  PowerPointApp: OLEVariant;
begin

  if opendialog1.Execute then begin
  
  try
    PowerPointApp := CreateOleObject('PowerPoint.Application');
  except
    ShowMessage('Error...');
    Exit;
  end;


  // Make Powerpoint visible
  PowerPointApp.Visible := true;

  // Show powerpoint version
  ShowMessage(Format('Powerpoint version: %s',[PowerPointApp.Version]));

  // Open a presentation 
  PowerPointApp.Presentations.Open(opendialog1.FileName, False, False, true);

  // Show number of slides
  ShowMessage(Format('%s slides.',[PowerPointApp.ActivePresentation.Slides.Count]));

  // Run the presentation 
  PowerPointApp.ActivePresentation.SlideShowSettings.Run; 

  // Go to next slide 
  PowerPointApp.ActivePresentation.SlideShowWindow.View.Next; 

  // Go to slide 2 
  PowerPointApp.ActivePresentation.SlideShowWindow.View.GoToSlide(2);

  // Go to previous slide
  PowerPointApp.ActivePresentation.SlideShowWindow.View.Previous;

  // Go to last slide
  PowerPointApp.ActivePresentation.SlideShowWindow.View.Last; 

  // Show current slide name 
  ShowMessage(Format('Current slidename: %s',[PowerPointApp.ActivePresentation.SlideShowWindow.View.Slide.Name])); 

  // Close Powerpoint 
  PowerPointApp.Quit; 
  PowerPointApp := UnAssigned; 
end;
end;


procedure TForm1.Button4Click(Sender: TObject);
begin
  close;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  PowerPointApp: OLEVariant;
begin
  try
    PowerPointApp := CreateOleObject('PowerPoint.Application');
  except
    ShowMessage('Error...');
    Exit;
  end;

  ShowMessage(Format('Powerpoint version: %s',[PowerPointApp.Version]));
  
  PowerPointApp.Quit; 
  PowerPointApp := UnAssigned; 
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -