原文地址:http://xxzqb.blog.163.com/blog/static/4122142920089249514506/
定义组件
ChooseWA: TWordApplication;
ChooseWD: TWordDocument;
ChooseWF: TWordFont;
定义组件
ChooseWA: TWordApplication;
ChooseWD: TWordDocument;
ChooseWF: TWordFont;
procedure TForm1.btn3Click(Sender: TObject);
var
ItemIndex: OleVariant;
filePath :OleVariant;
i,total:integer;
begin
ItemIndex := 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 do
begin
ChooseWD.comments.Item(total).Delete;
total:=ChooseWD.Comments.Count;
end;
ChooseWA.Visible :=true; //显示
end;