记录
一、安装pytho=docx库
python-docs 官方文档 python-docx — python-docx 1.1.2 文档
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple python-docx
。
二、实现功能
查找指定路径下后缀为docx所文件内的某个字符串,并输出相关信息。
实例
# -- coding: utf-8 --
import os
import glob
from docx import Document
def find_string_indocx(file_path,string):
doc = Document(file_path)
for paragraph in doc.paragraphs:
if string in paragraph.text:
print(paragraph.text);
#paragraph.text = paragraph.text.replace(old_string, new_string)//替换功能
for table in doc.tables:
for row in table.rows:
for cell in row.cells:
if string in cell.text:
for cell2 in row.cells: