You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
700 B

from docx import Document
def run_has_ole_object(run):
"""
检查run对象是否包含OLE对象
:param run: docx.text.run.Run对象
:return: bool
"""
# 检查run的XML中是否包含OLE对象标签
run_element = run._r
for child in run_element.iterchildren():
if child.tag.endswith('object') or child.tag.endswith('OLEObject'):
print(str(child))
return True
return False
# 测试代码
doc = Document(r'D:\dsWork\dsProject\dsRag\static\Txt\化学方程式_CHEMISTRY_1.docx')
for paragraph in doc.paragraphs:
for run in paragraph.runs:
if run_has_ole_object(run):
print("Found Ole")