delphi 利用Work 实现套打

本文介绍了一种使用VBA在Word文档中批量替换并删除批注的方法。通过加载指定模板,连接到文档,遍历所有批注,并将批注内容替换为指定文本,最后逐一删除批注。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文地址:http://xxzqb.blog.163.com/blog/static/4122142920089249514506/

定义组件
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;


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值