使用Python-docx把docx文档中的所有“李四”改为“李四”。

PyDocx.docx

attachments-2021-03-iho48xE460404649503db.png
一个有点类似的伪方法:

# 伪方法:python将一个单元格的文字颜色改为蓝色加粗

# Sroo 2021年2月19日17:15:38


from docx import Document

from docx.shared import RGBColor


document = Document('ttt.docx')

tables = document.tables[0]


#获取单元格原有文字

str00 = tables.cell(0,0).text

#清空该单元格

tables.cell(0,0).text = ""


#再添加原有文字,先清空后又添加,伪之所在

run = tables.cell(0,0).paragraphs[0].add_run(str00)

#run11 = tables.cell(0,0).add_paragraph(str00) # 添加段落


# 新加文字设置为蓝色且加粗

run.font.color.rgb = RGBColor(0,0,255)

run.bold = True

#run.italic = True



document.save('ttt.docx')


请先 登录 后评论
  • 0 关注
  • 0 收藏,391 浏览
  • sroo 提出于 2021-03-04 10:30

相似问题