python替换word中的关键文字

本文将介绍如何使用Python库,如`python-docx`,来读取、查找并替换Word文档中的特定关键字,实现自动化处理Word文件的需求。
摘要由CSDN通过智能技术生成

在word中替换关键文字

from win32com.client import Dispatch
import time


# def tihuan(before,content):
#     word = Dispatch('Word.Application')
#     doc = word.Documents.Open(r"E:\sxx\test2.docx")
#     word.Selection.Find.Execute(before, False, False, False, False, False, True, 1, True, content, 2)



f=open("mingdanB.txt")
i=0
for each in f:
    listeach=each.split("\t")
    time.sleep(1)
    word = Dispatch('Word.Application')
    doc = word.Documents.Open(r"E:\sxx\test.docx")

    word.Selection.Find.Execute("朱红", False, False, False, False, False, True, 1, True, listeach[0], 2)

    word.Selection.Find.Execute("SHA603", False, False, False, False, False, True, 1, True, listeach[1], 2)

    word.Selection.Find.Execute("2016.3.26-2017.12.31", False, False, False, False, False, True, 1, True, listeach[2], 2)

    word.Selection.Find.Execu
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值