unit UJoin_Word2;
interface
uses
//使用系统的单元文件
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleServer, Word2000, Buttons;
type
TForm1 = class(TForm)
//定义窗体上使用的组件
WordDocument1: TWordDocument;
Join_Btn: TBitBtn;
Save_Btn: TBitBtn;
Quit_Btn: TBitBtn;
Close_Btn: TBitBtn;
Label1: TLabel;
//定义事件处理过程
procedure Button1Click(Sender: TObject);
procedure Save_BtnClick(Sender: TObject);
procedure Quit_BtnClick(Sender: TObject);
procedure Close_BtnClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
//连接Word自动化服务器
begin
WordDocument1.Connect;
//调用TOleServer的Connect方法,启动作为自动化服务器的Word程序
try
WordDocument1.Content.Text := '欢迎你使用Word自动化服务器!';
//设置Word文档的内容
finally
// WordDocument1.Disconnect;
end;
end;
procedure TForm1.Save_BtnClick(Sender: TObject);
var
FileName : OleVariant;
//定义一个文件名变量
begin
FileName := 'c:/Mydocument.doc';
//设置输出文档的文件名
WordDocument1.SaveAs(FileName);
//调用SaveAs方法将文档按指定的文件名保存
end;
procedure TForm1.Quit_BtnClick(Sender: TObject);
begin
WordDocument1.Disconnect;
//断开与Word自动化服务器的连接
end;
procedure TForm1.Close_BtnClick(Sender: TObject);
begin
Form1.Close;
//关闭窗体,退出应用
end;
end.
使用TWordDocument组件连接Word自动化服务器
最新推荐文章于 2018-09-10 15:58:26 发布
本文介绍了一个使用Delphi实现的Word文档自动化操作案例,包括连接Word自动化服务器、修改文档内容、保存文档及断开连接等步骤。
1万+

被折叠的 条评论
为什么被折叠?



