以下是我在本機上所做的實驗
Windows XP+delphi
這個程序很簡單
unit main;
interface
//如果要使用CreateOleObject的辦法對WORD文檔進行操作
//語句中加入Comobj聲明和WordXP聲明
uses
Windows
Comobj
type
TForm
Button
Edit
procedure Button
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
// procedure Button
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form
//把這兩個變量聲明為全局變量
FWord: Variant;
FDoc: Variant;
implementation
{$R *
procedure TForm
begin
FWord
FWord
end;
procedure TForm
begin
//首先創建對象
try
FWord := CreateOleObject(
//WORD程序的執行是否可見
FWord
except
ShowMessage(
Exit;
end;
//先在打開的Word中創建一個新的頁面
try
FDoc := FWord
FWord
FWord
FWord
except
on e: Exception do
ShowMessage(e
end;
end;
//在程序關閉時把文件內容保存到當前目錄中
//同時關閉WORD程序
procedure TForm
begin
FDoc
FWord
FWord := Unassigned;
end;
end
此外
From:http://tw.wingwit.com/Article/program/Delphi/201311/24730.html