python-docx add_section 分栏不换页

python-docx 源码

    def add_section(self, start_type=WD_SECTION.NEW_PAGE):
        """
        Return a |Section| object representing a new section added at the end
        of the document. The optional *start_type* argument must be a member
        of the :ref:`WdSectionStart` enumeration, and defaults to
        ``WD_SECTION.NEW_PAGE`` if not provided.
        """
        new_sectPr = self._element.body.add_section_break()
        new_sectPr.start_type = start_type
        return Section(new_sectPr, self._part)
@alias('WD_SECTION')
class WD_SECTION_START(XmlEnumeration):
    """
    alias: **WD_SECTION**

    Specifies the start type of a section break.

    Example::

        from docx.enum.section import WD_SECTION

        section = document.sections[0]
        section.start_type = WD_SECTION.NEW_PAGE
    """

    __ms_name__ = 'WdSectionStart'

    __url__ = 'http://msdn.microsoft.com/en-us/library/office/ff840975.aspx'

    __members__ = (
        XmlMappedEnumMember(
            'CONTINUOUS', 0, 'continuous', 'Continuous section break.'
        ),
        XmlMappedEnumMember(
            'NEW_COLUMN', 1, 'nextColumn', 'New column section break.'
        ),
        XmlMappedEnumMember(
            'NEW_PAGE', 2, 'nextPage', 'New page section break.'
        ),
        XmlMappedEnumMember(
            'EVEN_PAGE', 3, 'evenPage', 'Even pages section break.'
        ),
        XmlMappedEnumMember(
            'ODD_PAGE', 4, 'oddPage', 'Section begins on next odd page.'
        ),
    )

所以分栏方式有5种,

  1. CONTINUOUS:连续分节。(尝试之后,这种就是不换页的)
  2. NEW_COLUMN:新的列分节符。(感觉和默认差不多,使用时没感觉有什么区别)
  3. NEW_PAGE:新的分页符。(默认的分栏方式)
  4. EVEN_PAGE:甚至连页数都是分节的。(感觉和默认差不多,使用时没感觉有什么区别)
  5. ODD_PAGE:部分从下一个奇数页开始。(感觉和默认差不多,使用时没感觉有什么区别)

示例

document.add_section(start_type=WD_SECTION_START.CONTINUOUS)

猜你喜欢

转载自blog.csdn.net/qq1261275789/article/details/126369630