delphi打开word以后,如何来响应word的关闭或其他事件(200分)

  • 主题发起人 主题发起人 ttt22703
  • 开始时间 开始时间
T

ttt22703

Unregistered / Unconfirmed
GUEST, unregistred user!
用以下带码打开的word
Word1:=CreateOleObject('Word.Application');
word1.Documents.Open(OpenDialog1.FileName,ReadOnly:=true) ;

如何来响应word的关闭事件呢,请教各位啦,最好有简单的源码
 
我给你一个小例子:
procedure TfrmPlag.BtnPrintClick(Sender: TObject);
Var
Y1,M1,D1:Word;
i,j:integer;
Vdate:OleVariant;

begin

try
WordAplag.Connect;
except
MessageDlg('Word may not be installed', mtError, [mbOk], 0);
Abort;
end;

WordAplag.Documents.AddOld(EmptyParam,EmptyParam);
DecodeDate(Now,Y1,M1,D1);

//******************* 写脚文件 *************************

WordAplag.Selection.TypeParagraph;
WordAplag.Selection.Font.Bold :=0;
WordAplag.Selection.Font.Size :=10;
WordAplag.Selection.ParagraphFormat.Alignment := wdAlignParagraphright;
Vdate :='打印人员:'+Auserinfo.UserName +
' 打印日期:'+formatdatetime('yyyy"年"mm"月"dd"日"',now);
WordAplag.ActiveDocument.sentences.Last.Text :=Vdate;
//******************* 写头文件 *************************
WordAplag.Selection.Font.Name :='宋体';
WordAplag.Selection.Font.Bold :=1;
WordAplag.Selection.Font.Size := 14;
WordAplag.Selection.ParagraphFormat.Alignment :=wdAlignParagraphCenter;

WordAplag.Selection.TypeText(inttostr(Y1)+'年'+inttostr(M1)+'月固定资产折旧表');

//*******************写正文部分 *************************
WordAplag.Selection.TypeParagraph;
WordAplag.Selection.Font.Size :=9;
WordAplag.Selection.ParagraphFormat.Alignment := wdAlignParagraphLeft;
WordAplag.Selection.Tables.AddOld(WordAplag.Selection.Get_Range ,Sgrdshow.Rowcount,10);
WordAplag.Selection.Cells.Width:=100;
for i:=1 to Sgrdshow.Colcount-1 do begin
for j:=0 to Sgrdshow.Rowcount-1 do begin
WordAplag.ActiveDocument.tables.Item(1).Cell(j+1,i).Range.Text :=Sgrdshow.Cells[i,j];
End ;

End;
WordAplag.Visible :=True;
WordAplag.Disconnect ;

end;
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=737517
看看这个有没有帮助
 
to Fangyizhi
我用CreateOleObject创建的word,可是用WordAplag.Selection.ParagraphFormat.Alignment := wdAlignParagraphright;时提示wdAlignParagraphright未定义,请指教。谢谢,另外我如何在任意地点插入文本啊?
 
后退
顶部