delphi 利用Work 实现套打
原文地址:http://xxzqb.blog.163.com/blog/static/4122142920089249514506/
定义组件
ChooseWA: TWordApplication;
ChooseWD: TWordDocument;
ChooseWF: TWordFont;
procedure TForm1.btn3Click(Sender: TObject); varItemIndex: OleVariant;filePath :OleVariant; i,total:integer;beginItemIndex := 1;filePath :='c://temp//test.dot'; //模板路径ChooseWA.Documents.Add(filePath,EmptyParam,EmptyParam,EmptyParam);ChooseWD.ConnectTo(ChooseWA.Documents.Item(ItemIndex));//ChooseWD.Range.InsertAfter('第一行数据'+#13);//#13代表换行 //插入数据total:=ChooseWD.Comments.Count; //批注总数for i:=1 to total do //替换批注内容begin ChooseWD.Comments.Item(i).Scope.Text :=mmo1.Text; //需从1开始end; //删除批注内容while total<>0 dobegin ChooseWD.comments.Item(total).Delete; total:=ChooseWD.Comments.Count;end; ChooseWA.Visible :=true; //显示end;