表示分页符的元素。PageBreak 可以包含在 ListItem 或 Paragraph 中,除非 ListItem 或 Paragraph 位于
Table、HeaderSection、FooterSection 或 FootnoteSection 中。PageBreak 本身不能包含任何其他元素。如需详细了解文档结构,
请参阅扩展 Google
文档指南。
方法
| 方法 | 返回值类型 | 简介 |
|---|---|---|
copy() | Page | 返回当前元素的分离式深层副本。 |
get | Object | 检索元素的属性。 |
get | Element|null | 检索元素的下一个同级元素。 |
get | Container | 检索元素的父元素。 |
get | Element|null | 检索元素的上一个同级元素。 |
get | Element | 检索元素的 Element。 |
is | Boolean | 确定元素是否位于 Document 的末尾。 |
remove | Page | 从父级元素中移除该元素。 |
set | Page | 设置元素的属性。 |
详细文档
copy()
getAttributes()
检索元素的属性。
结果是一个对象,其中包含每个有效元素属性的属性,每个属性名称对应于 DocumentApp.Attribute 枚举中的一项。
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody(); // Append a styled paragraph. const par = body.appendParagraph('A bold, italicized paragraph.'); par.setBold(true); par.setItalic(true); // Retrieve the paragraph's attributes. const atts = par.getAttributes(); // Log the paragraph attributes. for (const att in atts) { Logger.log(`${att}:${atts[att]}`); }
返回
Object - 元素的属性。
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getNextSibling()
getParent()
检索元素的父元素。
父元素包含当前元素。
返回
ContainerElement|null - 父元素。
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getPreviousSibling()
getType()
检索元素的 ElementType。
使用 getType() 确定给定元素的具体类型。
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody(); // Obtain the first element in the active tab's body. const firstChild = body.getChild(0); // Use getType() to determine the element's type. if (firstChild.getType() === DocumentApp.ElementType.PARAGRAPH) { Logger.log('The first element is a paragraph.'); } else { Logger.log('The first element is not a paragraph.'); }
返回
ElementType - 元素类型。
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
isAtDocumentEnd()
removeFromParent()
从父级元素中移除该元素。
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody(); // Remove all images in the active tab's body. const imgs = body.getImages(); for (let i = 0; i < imgs.length; i++) { imgs[i].removeFromParent(); }
返回
PageBreak|null - 移除的元素。
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
setAttributes(attributes)
设置元素的属性。
指定的 attributes 参数必须是一个对象,其中每个属性名称都是 DocumentApp.Attribute 枚举中的一项,每个属性值都是要应用的新值。
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody(); // Define a custom paragraph style. const style = {}; style[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] = DocumentApp.HorizontalAlignment.RIGHT; style[DocumentApp.Attribute.FONT_FAMILY] = 'Calibri'; style[DocumentApp.Attribute.FONT_SIZE] = 18; style[DocumentApp.Attribute.BOLD] = true; // Append a plain paragraph. const par = body.appendParagraph('A paragraph with custom style.'); // Apply the custom style. par.setAttributes(style);
参数
| 名称 | 类型 | 说明 |
|---|---|---|
attributes | Object | 元素的属性。 |
返回
PageBreak - 当前元素。
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents