How to reset page number to 1 in python-docx?

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-28 06:42:11

问题


I've added a Field 'Page' to my code using code:

def _add_field(run, field):
    """ add a field to a run
    """
    fldChar1 = OxmlElement('w:fldChar')  # creates a new element
    fldChar1.set(qn('w:fldCharType'), 'begin')  # sets attribute on element
    instrText = OxmlElement('w:instrText')
    instrText.set(qn('xml:space'), 'preserve')  # sets attribute on element
    instrText.text = field

    fldChar2 = OxmlElement('w:fldChar')
    fldChar2.set(qn('w:fldCharType'), 'separate')
    t = OxmlElement('w:t')
    t.text = "Right-click to update field."
    fldChar2.append(t)

    fldChar4 = OxmlElement('w:fldChar')
    fldChar4.set(qn('w:fldCharType'), 'end')

    r_element = run._r
    r_element.append(fldChar1)
    r_element.append(instrText)
    r_element.append(fldChar2)
    r_element.append(fldChar4)

def _add_number_range(run, name):
    """ add a number range field to a run
    """
    _add_field(run, r'SEQ %s \* ARABIC' % name)

Now as section is on page-3 of the document its getting number 3 and further pages get the page number as 4,5,...

How to reset this starting page number for that section as 1 from 3 using python-docx?

Here is the image of doing it from MSWord: Solution from MSWord

来源:https://stackoverflow.com/questions/57181035/how-to-reset-page-number-to-1-in-python-docx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!