请教:那位大侠熟悉利用Delphi进行Word编程,请发过来一段控制WORD的程序如何?谢谢!!!!(100分)

  • 主题发起人 主题发起人 DTiger
  • 开始时间 开始时间
D

DTiger

Unregistered / Unconfirmed
GUEST, unregistred user!
bjzxc@263.net
 
这个网站看看.
http://www.djpate.freeserve.co.uk/Automation.htm

找一份别人的,以前我的那份制作表格的没有找到.你自己去翻吧,查找'WORD'的已答问题.
或者是OLE/Automation分类的已答问题,有很多的足够你用了.看了后哪点不清楚再贴上来.
例如这个贴:http://www.delphibbs.com/delphibbs/dispq.asp?lid=609611
http://www.delphibbs.com/delphibbs/dispq.asp?lid=666382
http://www.delphibbs.com/delphibbs/dispq.asp?lid=115881


procedure TForm1.butSaveClick(Sender: TObject);
var
ItemIndex:OleVariant;
i,j: integer;
TempDoc,NewTempDoc,TempWord,TempEmpty:OleVariant;
TempW:OleVariant;
Temp1,Temp2,Temp3,Temp4:OleVariant;
TempTemp : string;
Tt : String;
T: OleVariant;
begin
try
for j := 0 to RzListView1.Items.Count-1 do
begin
TempEmpty := EmptyParam;
TempDoc := EmptyParam;
NewTempDoc := True;
ItemIndex := 1;
try
Wordapplication1.Connect;
except
MessageDlg('无法打开Word,请确认已安装Word。', mtError, [mbOk], 0);
Abort;
end;
//打开指定WORD文档
TempWord := Edit1.Text ;
//WordApplication1.Visible := True;
WordApplication1.Documents.Open(TempWord,TempEmpty,TempEmpty,
TempEmpty,TempEmpty,TempEmpty,TempEmpty,
TempEmpty,TempEmpty,TempEmpty);
TempDoc := EmptyParam;
NewTempDoc := False;

TempWord := wdGoToBookmark;
//方法:用Bookmarks;
//i := wordapplication1.ActiveDocument.Bookmarks.Count;
//showmessage(inttostr(i));

for i:= 0 to wordapplication1.ActiveDocument.Bookmarks.Count-1 do
begin
T := i+1;
TempEmpty := EmptyParam;
//取出bookmard的名字
TempW := WordApplication1.ActiveDocument.Bookmarks.Item(T).Name;
IF TempW = 'c' then
begin
TempTemp := RzListView1.Items[j].Caption;
wordapplication1.Selection.GoTo_(TempWord,TempEmpty,TempEmpty,TempW);
wordapplication1.Selection.TypeText(TempTemp);//'一个好人'
end;
if TempW = 'd' then
begin
TempTemp := RzListView1.Items[j].SubItems.Strings[0];
wordapplication1.Selection.GoTo_(TempWord,TempEmpty,TempEmpty,TempW);
wordapplication1.Selection.TypeText (TempTemp);//'一个好人';
end;
end;

//保存退出WORD
try
wordapplication1.ChangeFileOpenDirectory('C:/My Documents');
Temp1 := 'b.rtf';
Temp2 := wdFormatDocument;
Temp3 := '';
Temp4 := True;
TempW := False;
WordApplication1.ActiveDocument.SaveAs(Temp1,Temp2,TempW,
Temp3,Temp4,Temp3,TempW,TempW,TempW,TempW,TempW);
wordApplication1.Quit;
WordApplication1.Disconnect;
showmessage('保存成功');

except
on E: Exception do
begin
Showmessage(E.Message);
WordApplication1.Disconnect;
end;
end;
end;
except
on E: Exception do
begin
ShowMessage(E.Message);
WordApplication1.Disconnect;
end;
end;

end;
 
那个网站的东西很好,去看看,我就从那儿学了不少
 
后退
顶部