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.
19 lines
551 B
19 lines
551 B
from docx import Document
|
|
|
|
|
|
def extract_text_from_docx(file_path):
|
|
doc = Document(file_path)
|
|
formulas = []
|
|
|
|
for para in doc.paragraphs:
|
|
for run in para.runs:
|
|
if run.text: # 检查文本是否存在
|
|
formulas.append(run.text)
|
|
|
|
# 打印提取的公式
|
|
for index, formula in enumerate(formulas):
|
|
print(f'公式 {index + 1}: {formula}')
|
|
|
|
|
|
# 路径可替换为您的 Word 文档路径
|
|
extract_text_from_docx('D:\dsWork\dsProject\dsRag\Test\化学方程式_CHEMISTRY_1.docx') |