WPS 基础接口 > 文字 API 参考 > Section > Section 对象

代表所选内容、范围或文档中的一节。Section 对象是 Sections 集合的一个成员。Sections 集合包括所选内容、范围或文档中的所有节。

说明

使用 Sections(Index) 可返回一个 Section 对象,其中 Index 为索引号。以下示例更改活动文档第一节的左右页边距。

示例代码
let myPageSetup = ActiveDocument.Sections.Item(1).PageSetup
    myPageSetup.LeftMargin = InchesToPoints(0.5)
    myPageSetup.RightMargin = InchesToPoints(0.5)

使用 Add 方法或 InsertBreak 方法可向文档添加新节。以下示例在活动文档的开头添加新节。

示例代码
let myRange = ActiveDocument.Range(0, 0)
ActiveDocument.Sections.Add(myRange)
myRange.InsertParagraphAfter()

以下示例在所选内容的第一段上方添加一个分节符。

示例代码
Selection.Paragraphs.Item(1).Range.InsertBreak(wdSectionBreakContinuous)
注释
指定 Section 对象的 HeadersFooters 属性返回 HeadersFooters 对象。


请参阅