python修改word文本框中的内容
生活随笔
收集整理的這篇文章主要介紹了
python修改word文本框中的内容
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、背景和學習資料
這個問題持續困擾了我9天,一有空就查資料,終于解決了,必須記錄一下。
這期間還學習了的內容有:
1、phthon-docx的文檔,請參看:
https://python-docx.readthedocs.io/en/latest/index.html
2、網上資料:Python批量提取docx格式Word文檔中所有文本框內的文本
如:https://blog.csdn.net/dongfuguo/article/details/104825058
3、python修改xml節點中的文本
這個材料是幫助我最后解決問題的關鍵,盡管這個作者的排版和我一樣不怎么樣,哈哈~
https://blog.csdn.net/weixin_31936127/article/details/114953272
二、編寫代碼
document = Document('11.docx') children = document.element.body.iter() for child in children:if child.tag.endswith('txbx'): # child.tag.endswith('textbox') or txbxContentfor ci in child.iter():if ci.tag.endswith('main}t'):ci.text = '我被修改了!!'document.save('111.docx')三、效果
修改前:
修改后:
【The End】
總結
以上是生活随笔為你收集整理的python修改word文本框中的内容的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Maven Helper 安装使用
- 下一篇: JPEG 推荐的DC和AC系数的huff