相关疑难解决方法(0)

使用 python-docx 添加页码

我正在尝试使用 python-docx 在 word 文档的页脚中添加页码。到目前为止,我还没有找到如何做到这一点。这个问题解决了如何找到页码(或如何不能)。这个讨论创建一个模板并在那里添加页码。有没有办法在我使用 doc = Document() 创建的文档上添加页码?

python ms-word python-docx

6
推荐指数
4
解决办法
6811
查看次数

Python-docx:识别段落中的分页符

我逐段迭代文档,然后我将每个段落文本拆分为句子.(带空格的点)。与在整个段落文本中搜索相比,我将句子中的段落文本拆分为更有效的文本搜索

然后代码在句子的每个单词中搜索错误,错误来自纠错数据库。我在下面展示了一个简化的代码:

from docx.enum.text import WD_BREAK

for paragraph in document.paragraphs:
    sentences = paragraph.text.split('. ') 
    for sentence in sentences:
        words=sentence.split(' ')
        for word in words:
            for error in error_dictionary:
                 if error in word:
                     # (A) make simple replacement
                     word = word.replace(error, correction, 1)
                     # (B) alternative replacement based on runs 
                     for run in paragraph.runs:
                         if error in run.text:
                               run.text = run.text.replace(error, correction, 1)
                         # here we may fetch page break attribute and knowing current number …
Run Code Online (Sandbox Code Playgroud)

python search page-break python-docx

0
推荐指数
1
解决办法
4897
查看次数

标签 统计

python ×2

python-docx ×2

ms-word ×1

page-break ×1

search ×1