python docx学习笔记 Sections

Sections

  1. section的访问和添加
#1.访问全文所有sections,得到结果列表
sections = document.sections
#2.添加section
#之后添加的段落和内容都会位于该section中
new_section = document.add_section(WD_SECTION.ODD_PAGE)
  1. section的属性
#1.section.start_type
section.start_type = WD_SECTION.ODD_PAGE
#2.section.orientation, section.page_width, section.page_height
section.orientation = WD_ORIENT.LANDSCAPE
section.page_height = new_height
section.page_width = new_width
#3.section其他属性
section.left_margin, section.right_margin
section.top_margin, section.bottom_margin
section.gutter
section.header_distance, section.footer_distance
#举例
section.left_margin = Inches(1.5)
section.right_margin = Inches(1)

posted on 2022-05-23 17:00  朝朝暮Mu  阅读(523)  评论(0)    收藏  举报