# -*- coding: utf-8 -*-
# @Time : 2019/5/6 11:46
# @Author :
"""
# 利用python-docx替换文章中的内容
pip install python-docx
# 格式、线段、图片、页眉页脚等都不变
# python-docx 在处理超链接的问题时,可以参考一下链接对源码进行修改
https://github.com/python-openxml/python-docx/issues/85
# 具体修改操作如下
\site-packages\docx\oxml\__init__.py
# 需要新增的代码
def remove_hyperlink_tags(xml):
import re
text = xml.decode('utf-8')
text = text.replace("","")
text = re.sub(']*>', "", text)
return text.encode('utf-8')
# 需要修改的源码
def parse_xml(xml):
root_element = etree.fromstring(remove_hyperlink_tags(xml), oxml_parser)
return root_element
"""
import os
from docx import Document
from win32com import client
<