【问题标题】:How to Edit the Imported Word Document using python如何使用 python 编辑导入的 Word 文档
【发布时间】:2020-09-24 16:15:29
【问题描述】:

我确实有一个 Word 文档,我想对其进行编辑。这是文件的一部分。 【Word文档部分】:https://i.stack.imgur.com/g5JGO.jpg

我可以使用 python-docx 将它上传到 jupyter notebook。

我可以通过

访问每一行
import docx
doc = docx.Document('StudentReport.docx')
len(doc.paragraphs)
output- 31

print(doc.paragraphs[7].text)
output- 98% of Student have some access

所以我只想将 98% 更改为 85%。

【问题讨论】:

  • 你的问题不清楚。请添加您编写的代码并更好地解释所需的输出
  • 我编辑问题。我只是想知道,这些行如何编辑并将它们放在同一个地方?

标签: python-3.x pandas docx python-docx doc


【解决方案1】:

您可以简单地将其设置为:

doc.paragraphs[7].text = '85% of Student have some access'

如果你想对它更感兴趣:

doc.paragraphs[7].text = doc.paragraphs[7].text.replace('98%','85%')

【讨论】: