利用ole把word内签成自己的编辑器(200分)

  • 主题发起人 主题发起人 Ballion
  • 开始时间 开始时间
B

Ballion

Unregistered / Unconfirmed
GUEST, unregistred user!
各位前辈:
小弟在利用ole把word内签成自己的编辑器时,想把该编辑器做的完美一
点,使每次调用该编辑器时,自动调用一个word模板,打印时自己在向编辑好
的文件加入一些说明,查了许多资料,可是均不能找到,同word进行通信的资
料也太少,不知可否赐教!本人ICQ:18441233

 
可以调用Word中的Basic宏控制语言,你就可以干你想干的任何事情,这样吧,今天我有点忙,明天给你个简单的例子。OK?
 
看来 MS Word 还不够完美, 需要用 ole 使其更完美!

其实你要做的是用户化 MS Word, 应该安 Kiven 所说的在 VBA 上下一点功夫
 
二位说的有道理,

用Delphi调用word Basic,控制它调用你指定的模板,
而把你所需要的其它功能用VBA写在模板里.

想必Delphi调用Word Basic的例子你是知道的.(oleauto)
 
谢谢老兄们提供思路,不过我对VBA一点也不懂,不知那位可以提供一个简单的例子呢?
 
先看看 Delphi 3/demos/oleauto/autoctrl下面的例子,
然后找一些资料学一下VBA。
 
装word的时候加上wordbasic的help,那是全中文的。
编写得极好的,非常系统详尽。
 
我还是不成,时间挺长了,这样,谁给我一个小例子,这200分就是他的! 8)
 
Hehe, here is a simple exampe, I wrote it using VC, now I translate
it into Delphi, and I also learned some tech from Delphi4 sample.
hope it might help you.

uses
Word97;

var
WordObject : TWordObject;
WordBasicObject :
GetWordBasic()
procedure TForm1.BtnStartWordClick(Sender: TObject);
begin
if not Assigned(Word8Object) then begin
WordObject := TWordObject.Create;
with WordObject do begin
Visible := True;
OnQuit := AppQuit;
OnDocumentChange := AppDocumentChange;
OnNewDocument := DocNew;
OnOpenDocument := DocOpen;
OnCloseDocument := DocClose;

OpenDocument('Your template file name here'); {把您的模板文件打开}

end;
BtnStartWord.Enabled := False;
BtnClose.Enabled := True;
BtnNewDoc.Enabled := True;
end;
end;

procedure TForm1.BtnCloseClick(Sender: TObject);
begin
if Assigned(WordObject) then begin
BtnStartWord.Enabled := True;
BtnClose.Enabled := False;
BtnNewDoc.Enabled := False;
BtnTypeText.Enabled := False;
WordObject.Free;
WordObject := nil;
end;
end;

procedure TForm1.AppDocumentChange(Sender: TObject);
begin
Memo1.Lines.Add('Document changed');
BtnTypeText.Enabled := WordObject.Application.Documents.Count > 0;
end;

procedure TForm1.AppQuit(Sender: TObject);
begin
Memo1.Lines.Add('Quitting Word');
WordObject.Free;
WordObject := nil;
BtnStartWord.Enabled := True;
BtnClose.Enabled := False;
BtnNewDoc.Enabled := False;
BtnTypeText.Enabled := False;
end;

procedure TForm1.DocNew(Sender: TObject);
begin
Memo1.Lines.Add('New document');
end;

procedure TForm1.DocOpen(Sender: TObject);
begin
Memo1.Lines.Add('Document opened');
end;

procedure TForm1.DocClose(Sender: TObject);
begin
Memo1.Lines.Add('Document closed');
end;

procedure TForm1.BtnNewDocClick(Sender: TObject);
begin
try
WordObject.NewDoc('');
except
ShowMessage('It seems like somebody killed Word and didn''t tell me about it...');
if Assigned(WordObject) then begin
BtnStartWord.Enabled := True;
BtnClose.Enabled := False;
BtnNewDoc.Enabled := False;
BtnTypeText.Enabled := False;
WordObject.Free;
WordObject := nil;
end;
end;
end;

procedure TForm1.BtnTypeTextClick(Sender: TObject);
begin
WordObject.InsertText('This is pegasus speaking, :)'); { 插入您想输入的说明}
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if Assigned(WordObject) then begin
WordObject.Free;
WordObject := nil;
end;
end;


 
To use this demo, you need install Word97, then using Delphi to import the MSWord8.OLB,
and you need a Word97.pas unit to embed the Automation methods
around a TWordObject.

If you do not have this file, please reply this msg, then I can send to you, :)



 
多人接受答案了。
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部