Z
zsrobin
Unregistered / Unconfirmed
GUEST, unregistred user!
我有一些通知书,想在固定WORD文档的抬头插入来自数据库的一些文字后,
再用程序统一打印。请问具体操作如何呢? 我写了一些代码:
unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, OleServer, Word97;
type
TForm1 = class(TForm)
WordApplication: TWordApplication;
Button1: TButton;
WordDocument: TWordDocument;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var Template,NewTemplate,ItemIndex:OleVariant;
begin
try
Template := 'd:/normal.dot';
NewTemplate := true;
ItemIndex := 1;
try
Wordapplication.Connect;
except
MessageDlg('Word may not be installed', mtError, [mbOk], 0);
Abort;
end;
Wordapplication.Visible := True;
WordApplication.Caption := 'Delphi automation';
WordApplication.Documents.Add(Template,NewTemplate);
WordDocument.ConnectTo(WordApplication.Documents.Item(ItemIndex));
WordApplication.Options.CheckSpellingAsYouType := False;
WordApplication.Options.CheckGrammarAsYouType := False;
{Insert data}
WordDocument.Range.InsertAfter('大家好');
except
on E: Exception do
begin
ShowMessage(E.Message);
WordApplication.Disconnect;
end;
end;
end;
再用程序统一打印。请问具体操作如何呢? 我写了一些代码:
unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, OleServer, Word97;
type
TForm1 = class(TForm)
WordApplication: TWordApplication;
Button1: TButton;
WordDocument: TWordDocument;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var Template,NewTemplate,ItemIndex:OleVariant;
begin
try
Template := 'd:/normal.dot';
NewTemplate := true;
ItemIndex := 1;
try
Wordapplication.Connect;
except
MessageDlg('Word may not be installed', mtError, [mbOk], 0);
Abort;
end;
Wordapplication.Visible := True;
WordApplication.Caption := 'Delphi automation';
WordApplication.Documents.Add(Template,NewTemplate);
WordDocument.ConnectTo(WordApplication.Documents.Item(ItemIndex));
WordApplication.Options.CheckSpellingAsYouType := False;
WordApplication.Options.CheckGrammarAsYouType := False;
{Insert data}
WordDocument.Range.InsertAfter('大家好');
except
on E: Exception do
begin
ShowMessage(E.Message);
WordApplication.Disconnect;
end;
end;
end;