zoukankan      html  css  js  c++  java
  • 吴裕雄--天生自然python学习笔记:python文档操作自动查找替换 Word 文件中的指定文字

    Win32com 组件提供了自动替换 Word 文件中指定文字 的功能 。在使用“查找”
    功能替换文字之前,可先清除源文字及目标文字的格式,以免影响替换效果,语法为 :

    替换 Word 文件特定文字的语法为 :

     

    将指定目录中所有 Word 文件中的所有“方法”都替换为“ method ”。
    import os
    from win32com import client as client
    from win32com.client import constants
    
    word = client.gencache.EnsureDispatch('Word.Application')
    word.Visible = 1
    word.DisplayAlerts = 0
    # cpath=os.path.dirname(__file__)
    doc = word.Documents.Open("F:\pythonBase\pythonex\ch08\media\clipgraph.docx")
    word.Selection.Find.ClearFormatting()
    word.Selection.Find.Replacement.ClearFormatting()
    word.Selection.Find.Execute("方法",False,False,False,False,False,True,constants.wdFindContinue,False,"method",constants.wdReplaceAll)
    #doc.Close()
    #word.Quit()

  • 相关阅读:
    nlogn LIS CF1437E
    CF 1444B
    unsigned int慎用
    CF1425D 容斥 组合数 快速幂求逆元
    CF 1408D探照灯 找 匪
    各种状态转移
    CF 459C
    主席树 入门
    杭州特色景致的性价比精致餐厅
    SQL函数总结
  • 原文地址:https://www.cnblogs.com/tszr/p/12030318.html
Copyright © 2011-2022 走看看