Class FooterSection

FooterSection

表示页脚部分的元素。一个 Document 通常最多包含一个 FooterSectionFooterSection 可以包含 ListItemParagraphTable 元素。如需详细了解文档结构,请参阅扩展 Google 文档的指南

方法

方法返回类型简介
appendHorizontalRule()HorizontalRule创建并附加新的 HorizontalRule
appendImage(image)InlineImage根据指定的图像 blob 创建并附加新的 InlineImage
appendImage(image)InlineImage将给定的 InlineImage 附加到末尾。
appendListItem(listItem)ListItem将给定的 ListItem 附加到末尾。
appendListItem(text)ListItem创建并附加包含指定文本内容的新 ListItem
appendParagraph(paragraph)Paragraph将给定的 Paragraph 附加到末尾。
appendParagraph(text)Paragraph创建并附加包含指定文本内容的新 Paragraph
appendTable()Table创建并附加新的 Table
appendTable(cells)Table针对各个指定字符串值附加一个包含 TableCell 的新 Table
appendTable(table)Table将给定的 Table 附加到末尾。
clear()FooterSection清除元素的内容。
copy()FooterSection返回当前元素的已分离的深层副本。
editAsText()Text获取当前元素的 Text 版本,以用于修改。
findElement(elementType)RangeElement在元素的内容中搜索指定类型的后代。
findElement(elementType, from)RangeElement在元素内容中搜索指定类型的后代,从指定的 RangeElement 开始。
findText(searchPattern)RangeElement使用正则表达式在元素内容中搜索指定文本格式。
findText(searchPattern, from)RangeElement从指定搜索结果开始,搜索指定文本格式的元素内容。
getAttributes()Object检索元素的属性。
getChild(childIndex)Element检索指定子索引处的子元素。
getChildIndex(child)Integer检索指定子元素的子索引。
getImages()InlineImage[]检索相应部分中包含的所有 InlineImages
getListItems()ListItem[]检索相应部分中包含的所有 ListItems
getNumChildren()Integer检索子项的数量。
getParagraphs()Paragraph[]检索该部分中包含的所有 Paragraphs(包括 ListItems)。
getParent()ContainerElement获取元素的父元素。
getTables()Table[]检索相应部分中包含的所有 Tables
getText()String以文本字符串的形式检索元素的内容。
getTextAlignment()TextAlignment获取文本对齐方式。
getType()ElementType检索元素的 ElementType
insertHorizontalRule(childIndex)HorizontalRule在指定索引处创建并插入新的 HorizontalRule
insertImage(childIndex, image)InlineImage在指定索引处创建并插入从指定的图片 blob 中插入的 InlineImage
insertImage(childIndex, image)InlineImage在指定索引处插入指定的 InlineImage
insertListItem(childIndex, listItem)ListItem在指定索引处插入指定的 ListItem
insertListItem(childIndex, text)ListItem在指定索引处创建和插入包含指定文本内容的新 ListItem
insertParagraph(childIndex, paragraph)Paragraph在指定索引处插入指定的 Paragraph
insertParagraph(childIndex, text)Paragraph在指定索引处创建和插入包含指定文本内容的新 Paragraph
insertTable(childIndex)Table在指定索引处创建并插入新的 Table
insertTable(childIndex, cells)Table在指定索引处创建并插入包含指定单元格的新 Table
insertTable(childIndex, table)Table在指定索引处插入指定的 Table
removeChild(child)FooterSection移除指定的子元素。
removeFromParent()FooterSection将元素从其父项中移除。
replaceText(searchPattern, replacement)Element使用正则表达式将给定文本格式出现的所有项替换为指定的替换字符串。
setAttributes(attributes)FooterSection设置元素的属性。
setText(text)FooterSection将内容设置为纯文本。
setTextAlignment(textAlignment)FooterSection设置文本对齐方式。

详细文档

appendHorizontalRule()

创建并附加新的 HorizontalRule

HorizontalRule 将包含在新 Paragraph 中。

弃踢回攻

HorizontalRule - 新的水平规则

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

appendImage(image)

根据指定的图片 blob 创建并附加新的 InlineImage

此图片将包含在新 Paragraph 中。

参数

名称类型说明
imageBlobSource图片数据

弃踢回攻

InlineImage - 附加的图片

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

appendImage(image)

附加给定的 InlineImage

InlineImage 将包含在新 Paragraph 中。

在附加现有 InlineImage 的副本时,请使用此版本的 appendImage

参数

名称类型说明
imageInlineImage图片数据

弃踢回攻

InlineImage - 附加的图片

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

appendListItem(listItem)

附加给定的 ListItem

在附加现有 ListItem 的副本时,请使用此版本的 appendListItem

参数

名称类型说明
listItemListItem要附加的列表项

弃踢回攻

ListItem - 附加的列表项

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

appendListItem(text)

创建并附加包含指定文本内容的新 ListItem

系统会将连续列表项添加为同一列表的一部分。

参数

名称类型说明
textString列表项的文本内容

弃踢回攻

ListItem - 新的列表项

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

appendParagraph(paragraph)

附加给定的 Paragraph

在附加现有 Paragraph 的副本时,请使用此版本的 appendParagraph

参数

名称类型说明
paragraphParagraph要附加的段落

弃踢回攻

Paragraph - 附加段落

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

appendParagraph(text)

创建并附加包含指定文本内容的新 Paragraph

参数

名称类型说明
textString段落的文本内容

弃踢回攻

Paragraph - 新段落

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

appendTable()

创建并附加新的 Table

此方法还会在表格后附加一个空段落,因为 Google 文档文档不能以表格结尾。

弃踢回攻

Table - 新表

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

appendTable(cells)

针对各个指定字符串值附加一个包含 TableCell 的新 Table

此方法还会在表格后附加一个空段落,因为 Google 文档文档不能以表格结尾。

参数

名称类型说明
cellsString[][]要添加到新表格中的表格单元格的文本内容

弃踢回攻

Table - 附加表

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

appendTable(table)

附加给定的 Table

在附加现有 Table 的副本时,请使用此版本的 appendTable。此方法还会在表格后附加一个空段落,因为 Google 文档文档不能以表格结尾。

参数

名称类型说明
tableTable要附加的表

弃踢回攻

Table - 附加表

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

clear()

清除元素的内容。

弃踢回攻

FooterSection - 当前元素


copy()

返回当前元素的已分离深层副本。

元素中存在的所有子元素也会被复制。新元素没有父元素。

弃踢回攻

FooterSection - 新副本。

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

editAsText()

获取当前元素的 Text 版本,以用于修改。

使用 editAsText 将元素内容处理为富文本。editAsText 模式会忽略非文本元素(例如 InlineImageHorizontalRule)。

已删除文本范围内完全包含的子元素会从相应元素中移除。

var body = DocumentApp.getActiveDocument().getBody();

// Insert two paragraphs separated by a paragraph containing an
// horizontal rule.
body.insertParagraph(0, "An editAsText sample.");
body.insertHorizontalRule(0);
body.insertParagraph(0, "An example.");

// Delete " sample.\n\n An" removing the horizontal rule in the process.
body.editAsText().deleteText(14, 25);

弃踢回攻

Text - 当前元素的文本版本


findElement(elementType)

在元素的内容中搜索指定类型的后代。

参数

名称类型说明
elementTypeElementType要搜索的元素类型

弃踢回攻

RangeElement - 表示搜索元素位置的搜索结果

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

findElement(elementType, from)

在元素内容中搜索指定类型的后代,从指定的 RangeElement 开始。

// Get the body section of the active document.
var body = DocumentApp.getActiveDocument().getBody();

// Define the search parameters.
var searchType = DocumentApp.ElementType.PARAGRAPH;
var searchHeading = DocumentApp.ParagraphHeading.HEADING1;
var searchResult = null;

// Search until the paragraph is found.
while (searchResult = body.findElement(searchType, searchResult)) {
  var par = searchResult.getElement().asParagraph();
  if (par.getHeading() == searchHeading) {
    // Found one, update and stop.
    par.setText('This is the first header.');
    return;
  }
}

参数

名称类型说明
elementTypeElementType要搜索的元素类型
fromRangeElement要搜索的搜索结果

弃踢回攻

RangeElement - 表示搜索元素下一个位置的搜索结果

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

findText(searchPattern)

使用正则表达式在元素内容中搜索指定文本格式。

部分 JavaScript 正则表达式功能(如捕获组和模式修饰符)不完全受支持。

提供的正则表达式模式与当前元素中包含的每个文本块独立匹配。

参数

名称类型说明
searchPatternString要搜索的格式

弃踢回攻

RangeElement - 指示搜索文本位置的搜索结果,如果没有匹配项,则为 null

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

findText(searchPattern, from)

从指定搜索结果开始,搜索指定文本格式的元素内容。

部分 JavaScript 正则表达式功能(如捕获组和模式修饰符)不完全受支持。

提供的正则表达式模式与当前元素中包含的每个文本块独立匹配。

参数

名称类型说明
searchPatternString要搜索的格式
fromRangeElement要搜索的搜索结果

弃踢回攻

RangeElement - 指示搜索文本下一个位置的搜索结果,如果没有匹配项,则为 null

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getAttributes()

检索元素的属性。

结果会得到一个包含每个有效元素属性的属性的对象,其中每个属性名称对应 DocumentApp.Attribute 枚举中的一项。

var body = DocumentApp.getActiveDocument().getBody();

// Append a styled paragraph.
var par = body.appendParagraph('A bold, italicized paragraph.');
par.setBold(true);
par.setItalic(true);

// Retrieve the paragraph's attributes.
var atts = par.getAttributes();

// Log the paragraph attributes.
for (var att in atts) {
  Logger.log(att + ":" + atts[att]);
}

弃踢回攻

Object - 元素的属性。

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getChild(childIndex)

检索指定子索引处的子元素。

// Get the body section of the active document.
var body = DocumentApp.getActiveDocument().getBody();

// Obtain the first element in the document.
var firstChild = body.getChild(0);

// If it's a paragraph, set its contents.
if (firstChild.getType() == DocumentApp.ElementType.PARAGRAPH) {
  firstChild.asParagraph().setText("This is the first paragraph.");
}

参数

名称类型说明
childIndexInteger要检索的子元素的索引

弃踢回攻

Element - 指定索引处的子元素

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getChildIndex(child)

检索指定子元素的子索引。

参数

名称类型说明
childElement要为其检索索引的子元素

弃踢回攻

Integer - 子索引

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getImages()

检索相应部分中包含的所有 InlineImages

弃踢回攻

InlineImage[] - 版块图片

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getListItems()

检索相应部分中包含的所有 ListItems

弃踢回攻

ListItem[] - 版块列表项

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getNumChildren()

检索子项的数量。

// Get the body section of the active document.
var body = DocumentApp.getActiveDocument().getBody();

// Log the number of elements in the document.
Logger.log("There are " + body.getNumChildren() +
    " elements in the document body.");

弃踢回攻

Integer - 子级数量

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getParagraphs()

检索该部分中包含的所有 Paragraphs(包括 ListItems)。

弃踢回攻

Paragraph[] - 章节段落

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getParent()

获取元素的父元素。

父元素包含当前元素。

弃踢回攻

ContainerElement - 父元素。

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getTables()

检索相应部分中包含的所有 Tables

弃踢回攻

Table[] - 版块表格

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getText()

以文本字符串的形式检索元素的内容。

弃踢回攻

String - 文本字符串形式的元素内容

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getTextAlignment()

获取文本对齐方式。可用的对齐方式包括 DocumentApp.TextAlignment.NORMALDocumentApp.TextAlignment.SUBSCRIPTDocumentApp.TextAlignment.SUPERSCRIPT

弃踢回攻

TextAlignment - 文本对齐方式;如果文本包含多种类型的文本对齐方式或者从未设置文本对齐方式,则返回 null

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getType()

检索元素的 ElementType

使用 getType() 可确定给定元素的确切类型。

var body = DocumentApp.getActiveDocument().getBody();

// Obtain the first element in the document body.

var 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

insertHorizontalRule(childIndex)

在指定索引处创建并插入新的 HorizontalRule

HorizontalRule 将包含在新 Paragraph 中。

参数

名称类型说明
childIndexInteger要插入元素的索引

弃踢回攻

HorizontalRule - 新的水平规则

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

insertImage(childIndex, image)

在指定索引处创建并插入从指定的图片 blob 中插入的 InlineImage

参数

名称类型说明
childIndexInteger要插入元素的索引
imageBlobSource图片数据

弃踢回攻

InlineImage - 插入的内嵌图片

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

insertImage(childIndex, image)

在指定索引处插入指定的 InlineImage

此图片将包含在新 Paragraph 中。

参数

名称类型说明
childIndexInteger要插入元素的索引
imageInlineImage要插入的图片

弃踢回攻

InlineImage - 插入的内嵌图片

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

insertListItem(childIndex, listItem)

在指定索引处插入指定的 ListItem

参数

名称类型说明
childIndexInteger要插入的
listItemListItem要插入的列表项

弃踢回攻

ListItem - 插入的列表项

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

insertListItem(childIndex, text)

在指定索引处创建和插入包含指定文本内容的新 ListItem

参数

名称类型说明
childIndexInteger要插入的
textString列表项的文本内容

弃踢回攻

ListItem - 新的列表项

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

insertParagraph(childIndex, paragraph)

在指定索引处插入指定的 Paragraph

参数

名称类型说明
childIndexInteger要插入的
paragraphParagraph要插入的段落

弃踢回攻

Paragraph - 插入的段落

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

insertParagraph(childIndex, text)

在指定索引处创建和插入包含指定文本内容的新 Paragraph

参数

名称类型说明
childIndexInteger要插入的
textString段落的文本内容

弃踢回攻

Paragraph - 新段落

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

insertTable(childIndex)

在指定索引处创建并插入新的 Table

参数

名称类型说明
childIndexInteger要插入的

弃踢回攻

Table - 新表

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

insertTable(childIndex, cells)

在指定索引处创建并插入包含指定单元格的新 Table

参数

名称类型说明
childIndexInteger要插入的
cellsString[][]要添加到新表格中的表格单元格的文本内容

弃踢回攻

Table - 新表

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

insertTable(childIndex, table)

在指定索引处插入指定的 Table

参数

名称类型说明
childIndexInteger要插入的
tableTable要插入的表格

弃踢回攻

Table - 插入的表

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

removeChild(child)

移除指定的子元素。

参数

名称类型说明
childElement要移除的子元素

弃踢回攻

FooterSection - 当前元素

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

removeFromParent()

将元素从其父项中移除。

var body = DocumentApp.getActiveDocument().getBody();

// Remove all images in the document body.
var imgs = body.getImages();
for (var i = 0; i < imgs.length; i++) {
  imgs[i].removeFromParent();
}

弃踢回攻

FooterSection - 已移除的元素。

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

replaceText(searchPattern, replacement)

使用正则表达式将给定文本格式出现的所有项替换为指定的替换字符串。

搜索模式会以字符串(而非 JavaScript 正则表达式对象)的形式传递。 因此,您需要对格式中的所有反斜杠进行转义。

此方法使用 Google 的 RE2 正则表达式库,该库限制了支持的语法

提供的正则表达式模式会与当前元素中包含的每个文本块独立匹配。

var body = DocumentApp.getActiveDocument().getBody();

// Clear the text surrounding "Apps Script", with or without text.
body.replaceText("^.*Apps ?Script.*$", "Apps Script");

参数

名称类型说明
searchPatternString要搜索的正则表达式格式
replacementString要用作替换的文本

弃踢回攻

Element - 当前元素

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

setAttributes(attributes)

设置元素的属性。

指定的属性参数必须是一个对象,其中每个属性名称都是 DocumentApp.Attribute 枚举中的一个项,每个属性值都是要应用的新值。

var body = DocumentApp.getActiveDocument().getBody();

// Define a custom paragraph style.
var 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.
var par = body.appendParagraph('A paragraph with custom style.');

// Apply the custom style.
par.setAttributes(style);

参数

名称类型说明
attributesObject元素的属性。

弃踢回攻

FooterSection - 当前元素。

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

setText(text)

将内容设置为纯文本。

注意:现有内容将被清除。

参数

名称类型说明
textString新文本内容

弃踢回攻

FooterSection - 当前元素

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

setTextAlignment(textAlignment)

设置文本对齐方式。可用的对齐类型包括 DocumentApp.TextAlignment.NORMALDocumentApp.TextAlignment.SUBSCRIPTDocumentApp.TextAlignment.SUPERSCRIPT

// Make the entire first paragraph be superscript.
var text = DocumentApp.getActiveDocument().getBody().getParagraphs()[0].editAsText();
text.setTextAlignment(DocumentApp.TextAlignment.SUPERSCRIPT);

参数

名称类型说明
textAlignmentTextAlignment要应用的文本对齐方式类型

弃踢回攻

FooterSection - 当前元素

授权

使用此方法的脚本需要获得以下一个或多个范围的授权:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

已废弃的方法