Class Slide

幻灯片

演示文稿中的幻灯片。

这些网页包含您向观众展示的内容。大多数幻灯片都基于母版和布局。您可以在创建幻灯片时指定要为每张幻灯片使用哪个布局。

方法

方法返回类型简介
duplicate()Slide复制幻灯片。
getBackground()PageBackground获取网页的背景。
getColorScheme()ColorScheme获取与网页关联的 ColorScheme
getGroups()Group[]返回页面上 Group 对象的列表。
getImages()Image[]返回页面上 Image 对象的列表。
getLayout()Layout|null获取幻灯片所基于的布局,如果幻灯片不是基于布局,则返回 null
getLines()Line[]返回页面上 Line 对象的列表。
getNotesPage()NotesPage返回与幻灯片关联的备注页。
getObjectId()String获取网页的唯一 ID。
getPageElementById(id)PageElement|null返回具有指定 ID 的页面上的 PageElement,如果不存在,则返回 null
getPageElements()PageElement[]返回页面上呈现的 PageElement 对象列表。
getPageType()PageType获取网页的类型。
getPlaceholder(placeholderType)PageElement|null返回指定 PlaceholderType 的占位符 PageElement 对象,如果不存在匹配的占位符,则返回 null
getPlaceholder(placeholderType, placeholderIndex)PageElement|null返回指定 PlaceholderType 和占位符索引的占位符 PageElement 对象;如果占位符不存在,则返回 null
getPlaceholders()PageElement[]返回网页中占位符 PageElement 对象的列表。
getShapes()Shape[]返回页面上 Shape 对象的列表。
getSheetsCharts()SheetsChart[]返回页面上 SheetsChart 对象的列表。
getSlideLinkingMode()SlideLinkingMode返回一个 SlideLinkingMode,用于指明幻灯片是否已链接到另一张幻灯片。
getSourcePresentationId()String返回源 Presentation ID;如果幻灯片未关联,则返回 null
getSourceSlideObjectId()String返回源幻灯片 ID;如果幻灯片未关联,则返回 null
getTables()Table[]返回页面上 Table 对象的列表。
getVideos()Video[]返回页面上 Video 对象的列表。
getWordArts()WordArt[]返回页面上 WordArt 对象的列表。
group(pageElements)Group将所有指定的页面元素分组。
insertGroup(group)Group在网页中插入所提供 Group 的副本。
insertImage(blobSource)Image在页面左上角插入指定图片 blob 中的默认大小的图片。
insertImage(blobSource, left, top, width, height)Image在页面上插入指定图片 blob 中具有所提供位置和大小的图片。
insertImage(image)Image在网页中插入所提供 Image 的副本。
insertImage(imageUrl)Image使用提供的网址在页面左上角插入默认大小的图片。
insertImage(imageUrl, left, top, width, height)Image在网页上插入一张图片,该图片具有指定的位置和大小,并来自指定的网址。
insertLine(line)Line在网页中插入所提供 Line 的副本。
insertLine(lineCategory, startConnectionSite, endConnectionSite)Line在页面上插入一条连接两个 connection sites 的线。
insertLine(lineCategory, startLeft, startTop, endLeft, endTop)Line在网页上插入一条线。
insertPageElement(pageElement)PageElement在网页中插入所提供 PageElement 的副本。
insertShape(shape)Shape在网页中插入所提供 Shape 的副本。
insertShape(shapeType)Shape在页面上插入形状。
insertShape(shapeType, left, top, width, height)Shape在页面上插入形状。
insertSheetsChart(sourceChart)SheetsChart在网页上插入 Google 表格图表。
insertSheetsChart(sourceChart, left, top, width, height)SheetsChart在页面上插入具有指定位置和大小的 Google 表格图表。
insertSheetsChart(sheetsChart)SheetsChart在网页中插入所提供 SheetsChart 的副本。
insertSheetsChartAsImage(sourceChart)Image将 Google 表格图表作为 Image 插入到网页中。
insertSheetsChartAsImage(sourceChart, left, top, width, height)Image将 Google 表格图表作为 Image 插入到网页中,并具有提供的位置和大小。
insertTable(numRows, numColumns)Table在网页上插入表格。
insertTable(numRows, numColumns, left, top, width, height)Table在页面上插入具有指定位置和大小的表格。
insertTable(table)Table在网页中插入所提供 Table 的副本。
insertTextBox(text)Shape在网页上插入一个包含所提供字符串的文本框 Shape
insertTextBox(text, left, top, width, height)Shape在网页上插入一个包含所提供字符串的文本框 Shape
insertVideo(videoUrl)Video在页面左上角插入一个具有默认大小的视频。
insertVideo(videoUrl, left, top, width, height)Video在网页上插入具有指定位置和大小的视频。
insertVideo(video)Video在网页中插入所提供 Video 的副本。
insertWordArt(wordArt)WordArt在网页中插入所提供 WordArt 的副本。
isSkipped()Boolean返回相应幻灯片在演示模式下是否会被跳过。
move(index)void将幻灯片移动到指定索引。
refreshSlide()void刷新幻灯片,以反映对链接的源幻灯片所做的任何更改。
remove()void移除相应页面。
replaceAllText(findText, replaceText)Integer将与查找文本匹配的所有文本实例替换为替换文本。
replaceAllText(findText, replaceText, matchCase)Integer将与查找文本匹配的所有文本实例替换为替换文本。
selectAsCurrentPage()void选择当前演示中的 Page 作为 current page selection,并移除任何之前的选择。
setSkipped(isSkipped)void设置在演示模式下是否跳过相应幻灯片。
unlink()void取消当前 Slide 与其来源幻灯片的关联。

详细文档

duplicate()

复制幻灯片。

系统会立即在原幻灯片后面创建重复的幻灯片。

返回

Slide - 复制的幻灯片。

授权

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

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

getBackground()

获取网页的背景。

返回

PageBackground - 页面的背景。

授权

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

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

getColorScheme()

获取与网页关联的 ColorScheme

返回

ColorScheme - 网页的配色方案。

授权

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

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

getGroups()

返回页面上 Group 对象的列表。

返回

Group[]

授权

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

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

getImages()

返回页面上 Image 对象的列表。

返回

Image[]

授权

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

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

getLayout()

获取幻灯片所基于的布局,如果幻灯片不是基于布局,则返回 null

返回

Layout|null

授权

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

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

getLines()

返回页面上 Line 对象的列表。

返回

Line[]

授权

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

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

getNotesPage()

返回与幻灯片关联的备注页。

返回

NotesPage

授权

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

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

getObjectId()

获取网页的唯一 ID。网页和网页元素使用的对象 ID 共享同一命名空间。

返回

String

授权

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

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

getPageElementById(id)

返回具有指定 ID 的页面上的 PageElement,如果不存在,则返回 null

参数

名称类型说明
idString要检索的页面元素的 ID。

返回

PageElement|null - 具有指定 ID 的页面元素。

授权

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

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

getPageElements()

返回页面上呈现的 PageElement 对象列表。

返回

PageElement[]

授权

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

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

getPageType()

获取网页的类型。

返回

PageType - 网页类型。

授权

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

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

getPlaceholder(placeholderType)

返回指定 PlaceholderType 的占位符 PageElement 对象,如果不存在匹配的占位符,则返回 null

如果存在多个相同类型的占位符,则返回占位符索引最小的那个。如果存在多个具有相同索引的匹配占位符,则返回网页的网页元素集合中的第一个占位符。

const slide = SlidesApp.getActivePresentation().getSlides()[0];
const placeholder = slide.getPlaceholder(
    SlidesApp.PlaceholderType.CENTERED_TITLE,
);

参数

名称类型说明
placeholderTypePlaceholderType

返回

PageElement|null

授权

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

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

getPlaceholder(placeholderType, placeholderIndex)

返回指定 PlaceholderType 和占位索引的占位 PageElement 对象,如果不存在占位,则返回 null

如果存在多个具有相同类型和索引的占位符,则返回网页的网页元素集合中的第一个占位符。

const slide = SlidesApp.getActivePresentation().getSlides()[0];
const placeholder = slide.getPlaceholder(
    SlidesApp.PlaceholderType.CENTERED_TITLE,
    0,
);

参数

名称类型说明
placeholderTypePlaceholderType
placeholderIndexInteger

返回

PageElement|null

授权

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

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

getPlaceholders()

返回网页中占位符 PageElement 对象的列表。

const master = SlidesApp.getActivePresentation().getMasters()[0];
Logger.log(
    `Number of placeholders in the master: ${master.getPlaceholders().length}`,
);

返回

PageElement[]

授权

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

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

getShapes()

返回页面上 Shape 对象的列表。

返回

Shape[]

授权

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

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

getSheetsCharts()

返回页面上 SheetsChart 对象的列表。

返回

SheetsChart[]

授权

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

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

getSlideLinkingMode()

返回一个 SlideLinkingMode,用于指明幻灯片是否已链接到另一张幻灯片。

返回

SlideLinkingMode - 幻灯片关联模式。

授权

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

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

getSourcePresentationId()

返回源 Presentation ID;如果幻灯片未关联,则返回 null

只有当幻灯片链接到其他演示文稿中的幻灯片时,它才具有源 Presentation ID。

返回

String - 源演示 ID 或 null

授权

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

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

getSourceSlideObjectId()

返回源幻灯片 ID;如果幻灯片未关联,则返回 null

只有当幻灯片链接到其他演示文稿中的幻灯片时,它才具有源幻灯片 ID。

返回

String - 源幻灯片 ID 或 null

授权

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

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

getTables()

返回页面上 Table 对象的列表。

返回

Table[]

授权

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

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

getVideos()

返回页面上 Video 对象的列表。

返回

Video[]

授权

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

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

getWordArts()

返回页面上 WordArt 对象的列表。

返回

WordArt[]

授权

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

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

group(pageElements)

将所有指定的页面元素分组。

同一网页上应至少有两个尚未归入其他组的网页元素。某些网页元素(例如 VideosTablesplaceholder Shapes)无法分组。

参数

名称类型说明
pageElementsPageElement[]要分组在一起的元素。

返回

Group - 新群组。

授权

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

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

insertGroup(group)

在网页上插入所提供 Group 的副本。

插入的元素在此页面上的位置由源元素在其相应页面上的位置决定。

如果所提供的元素是从当前演示文稿中复制的占位符,则从母版页或布局页继承的属性也会在插入的元素上继承。

如果所提供的元素是从其他演示中复制的占位符,则从源演示中继承自母版页或布局页的属性会被复制到该元素中。

// Copy a group between presentations.
const otherPresentationSlide =
    SlidesApp.openById('presentationId').getSlides()[0];
const currentPresentationSlide =
    SlidesApp.getActivePresentation().getSlides()[0];
const group = otherPresentationSlide.getGroups()[0];
currentPresentationSlide.insertGroup(
    group);  // Also available for Layout, Master, and Page.

参数

名称类型说明
groupGroup要复制和插入的群组。

返回

Group - 插入的群组。

授权

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

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

insertImage(blobSource)

在页面左上角插入指定图片 blob 中的默认大小的图片。

插入图片时,系统会从 BlobSource 中提取一次图片,并存储一份副本以在演示文稿中显示。图片大小必须小于 50MB,像素数不得超过 2500 万,且必须为 PNG、JPEG 或 GIF 格式。

const slide = SlidesApp.getActivePresentation().getSlides()[0];
// Get the Drive image file with the given ID.
const image = DriveApp.getFileById('123abc');
slide.insertImage(image);

参数

名称类型说明
blobSourceBlobSource图片数据。

返回

Image - 插入的图片。

授权

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

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

insertImage(blobSource, left, top, width, height)

在页面上插入指定图片 blob 中具有所提供位置和大小的图片。

系统会在插入时从提供的 BlobSource 中提取一次图片,并存储一份副本以在演示文稿中显示。图片的大小必须小于 50MB,像素数不得超过 2500 万,且必须为 PNG、JPEG 或 GIF 格式。

为了保持图片的宽高比,系统会根据所提供的大小对图片进行缩放和居中。

const slide = SlidesApp.getActivePresentation().getSlides()[0];
// Get the Drive image file with the given ID.
const image = DriveApp.getFileById('123abc');
const position = {
  left: 0,
  top: 0
};
const size = {
  width: 300,
  height: 100
};
slide.insertImage(image, position.left, position.top, size.width, size.height);

参数

名称类型说明
blobSourceBlobSource图片数据。
leftNumber图片在页面上的水平位置(以点为单位),从页面左上角开始测量。
topNumber图片在页面中的垂直位置(以点为单位),从页面左上角开始测量。
widthNumber图片的宽度(以点为单位)。
heightNumber图片的高度(以点为单位)。

返回

Image - 插入的图片。

授权

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

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

insertImage(image)

在网页上插入所提供 Image 的副本。

此页面上插入的图片的位置由源图片在其相应页面上的位置决定。

如果提供的图片是从当前演示文稿中复制的占位图片,则从母版页或布局页继承的属性也会继承到插入的图片中。

如果提供的图片是从其他演示中复制的占位图片,则从源演示中继承自母版页或布局页的属性会被复制到该图片中。如果复制的占位图片为空,则不会在目标演示文稿中插入任何内容。

// Copy an image between presentations.
const otherPresentationSlide =
    SlidesApp.openById('presentationId').getSlides()[0];
const currentPresentationSlide =
    SlidesApp.getActivePresentation().getSlides()[0];
const image = otherPresentationSlide.getImages[0];
currentPresentationSlide.insertImage(image);

参数

名称类型说明
imageImage要复制和插入的图片。

返回

Image - 插入的图片。

授权

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

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

insertImage(imageUrl)

在页面左上角插入一张默认大小的图片,图片来自提供的网址。

插入图片时,系统会从相应网址获取图片一次,并存储一份副本以在演示中显示。图片大小不得超过 50MB,像素数不得超过 2500 万,且必须为 PNG、JPEG 或 GIF 格式。

所提供的网址必须可以公开访问,且不得大于 2kB。网址本身会与图片一起保存,并通过 Image.getSourceUrl() 公开。

参数

名称类型说明
imageUrlString图片网址。

返回

Image - 插入的图片。

授权

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

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

insertImage(imageUrl, left, top, width, height)

在网页上插入一张图片,该图片具有指定的位置和大小,并来自指定的网址。

插入图片时,系统会从相应网址获取图片一次,并存储一份副本以在演示中显示。图片大小不得超过 50MB,像素数不得超过 2500 万,且必须为 PNG、JPEG 或 GIF 格式。

所提供的网址必须可以公开访问,且不得大于 2kB。网址本身会与图片一起保存,并通过 Image.getSourceUrl() 公开。

为了保持图片的宽高比,系统会根据所提供的大小对图片进行缩放和居中。

参数

名称类型说明
imageUrlString图片网址。
leftNumber图片在页面上的水平位置(以点为单位),从页面左上角开始测量。
topNumber图片在页面中的垂直位置(以点为单位),从页面左上角开始测量。
widthNumber图片的宽度(以点为单位)。
heightNumber图片的高度(以点为单位)。

返回

Image - 插入的图片。

授权

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

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

insertLine(line)

在网页上插入所提供 Line 的副本。

插入的元素在此页面上的位置由源元素在其相应页面上的位置决定。

如果所提供的元素是从当前演示文稿中复制的占位符,则从母版页或布局页继承的属性也会在插入的元素上继承。

如果所提供的元素是从其他演示中复制的占位符,则从源演示中继承自母版页或布局页的属性会被复制到该元素中。

// Copy a line between presentations.
const otherPresentationSlide =
    SlidesApp.openById('presentationId').getSlides()[0];
const currentPresentationSlide =
    SlidesApp.getActivePresentation().getSlides()[0];
const line = otherPresentationSlide.getLines[0];
currentPresentationSlide.insertLine(line);

参数

名称类型说明
lineLine要复制和插入的行。

返回

Line - 插入的行。

授权

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

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

insertLine(lineCategory, startConnectionSite, endConnectionSite)

在页面上插入一条连接两个 connection sites 的线。两个连接网站必须位于此页面上。

// Insert a line in the first slide of the presentation connecting two shapes.
const slide = SlidesApp.getActivePresentation().getSlides()[0];
const shape1 = slide.insertShape(SlidesApp.ShapeType.RECTANGLE);
const shape2 = slide.insertShape(SlidesApp.ShapeType.CLOUD);
slide.insertLine(
    SlidesApp.LineCategory.BENT,
    shape1.getConnectionSites()[0],
    shape2.getConnectionSites()[1],
);

参数

名称类型说明
lineCategoryLineCategory要插入的行的类别。
startConnectionSiteConnectionSite线段起点要连接到的连接位置。
endConnectionSiteConnectionSite要连接线路末端的连接站点。

返回

Line - 插入的行。

授权

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

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

insertLine(lineCategory, startLeft, startTop, endLeft, endTop)

在网页上插入一条线。

// Insert a line in the first slide of the presentation.
const slide = SlidesApp.getActivePresentation().getSlides()[0];
const startPoint = {
  left: 10,
  top: 10
};
const endPoint = {
  left: 40,
  top: 40
};
slide.insertLine(
    SlidesApp.LineCategory.STRAIGHT,
    startPoint.left,
    startPoint.top,
    endPoint.left,
    endPoint.top,
);

参数

名称类型说明
lineCategoryLineCategory要插入的行的类别。
startLeftNumber线条起点的水平位置,以点为单位,从页面左上角开始测量。
startTopNumber线条起点的垂直位置,以点为单位,从页面左上角开始测量。
endLeftNumber线条端点的水平位置,以点为单位,从页面左上角开始测量。
endTopNumber线条端点的垂直位置,以点为单位从页面左上角开始测量。

返回

Line - 插入的行。

授权

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

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

insertPageElement(pageElement)

在网页上插入所提供 PageElement 的副本。

插入的元素在此页面上的位置由源元素在其相应页面上的位置决定。

如果所提供的元素是从当前演示文稿中复制的占位符,则从母版页或布局页继承的属性也会在插入的元素上继承。

如果所提供的元素是从其他演示中复制的占位符,则从源演示中继承自母版页或布局页的属性会被复制到该元素中。

// Copy a page element between presentations.
const otherPresentationSlide =
    SlidesApp.openById('presentationId').getSlides()[0];
const currentPresentationSlide =
    SlidesApp.getActivePresentation().getSlides()[0];
const pageElement = otherPresentationSlide.getPageElements()[0];

// Also available for Layout, Master, and Page.
currentPresentationSlide.insertPageElement(pageElement);

参数

名称类型说明
pageElementPageElement要复制和插入的页面元素。

返回

PageElement - 插入的页面元素。

授权

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

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

insertShape(shape)

在网页上插入所提供 Shape 的副本。

插入的元素在此页面上的位置由源元素在其相应页面上的位置决定。

如果所提供的元素是从当前演示文稿中复制的占位符,则从母版页或布局页继承的属性也会在插入的元素上继承。

如果所提供的元素是从其他演示中复制的占位符,则从源演示中继承自母版页或布局页的属性会被复制到该元素中。

// Copy a shape between presentations.
const otherPresentationSlide =
    SlidesApp.openById('presentationId').getSlides()[0];
const currentPresentationSlide =
    SlidesApp.getActivePresentation().getSlides()[0];
const shape = otherPresentationSlide.getShapes[0];
currentPresentationSlide.insertShape(
    shape);  // Also available for Layout, Master, and Page.

参数

名称类型说明
shapeShape要复制和插入的形状。

返回

Shape - 插入的形状。

授权

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

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

insertShape(shapeType)

在页面上插入形状。

系统会以默认大小将形状插入到页面左上角。

// Insert a shape in the first slide of the presentation.
const slide = SlidesApp.getActivePresentation().getSlides()[0];

// Also available for Layout, Master, and Page.
slide.insertShape(SlidesApp.ShapeType.RECTANGLE);

参数

名称类型说明
shapeTypeShapeType要插入的形状的类型。

返回

Shape - 插入的形状。

授权

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

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

insertShape(shapeType, left, top, width, height)

在页面上插入形状。

参数

名称类型说明
shapeTypeShapeType要插入的形状的类型。
leftNumber形状的水平位置,从页面左上角开始测量。
topNumber形状的纵向位置,从页面左上角开始测量。
widthNumber形状的宽度。
heightNumber形状的高度。

返回

Shape - 插入的形状。

授权

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

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

insertSheetsChart(sourceChart)

在网页上插入 Google 表格图表。

图表会以默认大小插入到页面左上角。

插入的图表与源 Google 表格图表相关联,因此可以进行更新。其他协作者可以查看指向源电子表格的链接。

const sheet = SpreadsheetApp.openById('spreadsheetId').getSheets()[0];
const chart = sheet.getCharts()[0];
// Insert the spreadsheet chart in the first slide.
const slide = SlidesApp.getActivePresentation().getSlides()[0];
slide.insertSheetsChart(chart);

参数

名称类型说明
sourceChartEmbeddedChart要插入到网页中的电子表格中的图表。

返回

SheetsChart - 网页中插入的图表。

授权

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

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

insertSheetsChart(sourceChart, left, top, width, height)

在页面上插入具有指定位置和大小的 Google 表格图表。

为了保持图表的宽高比,系统会根据所提供的大小对图表进行缩放和居中。

插入的图表与源 Google 表格图表相关联,因此可以进行更新。其他协作者可以查看指向源电子表格的链接。

const sheet = SpreadsheetApp.openById('spreadsheetId').getSheets()[0];
const chart = sheet.getCharts()[0];
// Insert the spreadsheet chart in the first slide.
const slide = SlidesApp.getActivePresentation().getSlides()[0];
const position = {
  left: 0,
  top: 0
};
const size = {
  width: 200,
  height: 200
};

// Also available for Layout, Master, and Page.
slide.insertSheetsChart(
    chart,
    position.left,
    position.top,
    size.width,
    size.height,
);

参数

名称类型说明
sourceChartEmbeddedChart要插入到网页中的电子表格中的图表。
leftNumber图表的水平位置(以点为单位),从页面的左上角开始测量。
topNumber图表的垂直位置(以点为单位),从网页的左上角开始测量。
widthNumber图表的宽度(以点为单位)。
heightNumber图表的高度(以点为单位)。

返回

SheetsChart - 网页中插入的图表。

授权

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

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

insertSheetsChart(sheetsChart)

在网页上插入所提供 SheetsChart 的副本。

插入的元素在此页面上的位置由源元素在其相应页面上的位置决定。

如果所提供的元素是从当前演示文稿中复制的占位符,则从母版页或布局页继承的属性也会在插入的元素上继承。

如果所提供的元素是从其他演示中复制的占位符,则从源演示中继承自母版页或布局页的属性会被复制到该元素中。

// Copy a sheets chart between presentations.
const otherPresentationSlide =
    SlidesApp.openById('presentationId').getSlides()[0];
const currentPresentationSlide =
    SlidesApp.getActivePresentation().getSlides()[0];
const sheetsChart = otherPresentationSlide.getSheetsCharts[0];

// Also available for Layout, Master, and Page.
currentPresentationSlide.insertSheetsChart(sheetsChart);

参数

名称类型说明
sheetsChartSheetsChart要复制和插入的 Google 表格图表。

返回

SheetsChart - 插入的工作表图表。

授权

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

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

insertSheetsChartAsImage(sourceChart)

将 Google 表格图表作为 Image 插入到网页中。

图表的图片会以默认大小插入到页面左上角。

插入的图表图片未与源 Google 表格图表相关联。

const sheet = SpreadsheetApp.openById('spreadsheetId').getSheets()[0];
const chart = sheet.getCharts()[0];
// Insert the spreadsheet chart in the first slide.
const slide = SlidesApp.getActivePresentation().getSlides()[0];
slide.insertSheetsChartAsImage(
    chart);  // Also available for Layout, Master, and Page.

参数

名称类型说明
sourceChartEmbeddedChart要插入到网页中的电子表格中的图表。

返回

Image - 网页中插入的图表图片。

授权

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

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

insertSheetsChartAsImage(sourceChart, left, top, width, height)

将 Google 表格图表作为 Image 插入到网页中,并具有指定的位置和大小。

为了保持图表图片的宽高比,系统会根据所提供的大小对图片进行缩放和居中。

插入的图表图片未与源 Google 表格图表相关联。

const sheet = SpreadsheetApp.openById('spreadsheetId').getSheets()[0];
const chart = sheet.getCharts()[0];
// Insert the spreadsheet chart in the first slide.
const slide = SlidesApp.getActivePresentation().getSlides()[0];
const position = {
  left: 0,
  top: 0
};
const size = {
  width: 200,
  height: 200
};

// Also available for Layout, Master, and Page.
slide.insertSheetsChartAsImage(
    chart,
    position.left,
    position.right,
    size.width,
    size.height,
);

参数

名称类型说明
sourceChartEmbeddedChart要插入到网页中的电子表格中的图表。
leftNumber图表的水平位置(以点为单位),从页面的左上角开始测量。
topNumber图表的垂直位置(以点为单位),从网页的左上角开始测量。
widthNumber图表的宽度(以点为单位)。
heightNumber图表的高度(以点为单位)。

返回

Image - 网页中插入的图表图片。

授权

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

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

insertTable(numRows, numColumns)

在网页上插入表格。

表格居中显示在网页上,具有默认大小,行和列均匀分布。

参数

名称类型说明
numRowsInteger表中的行数。
numColumnsInteger表中的列数。

返回

Table - 插入的表格。

授权

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

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

insertTable(numRows, numColumns, left, top, width, height)

在页面上插入具有指定位置和大小的表格。

创建的表格中的行和列均匀分布。

参数

名称类型说明
numRowsInteger表中的行数。
numColumnsInteger表中的列数。
leftNumber表格的水平位置,从页面左上角开始测量。
topNumber表格的纵向位置,从页面左上角开始测量。
widthNumber表格的宽度。
heightNumber表格的最小高度。渲染后的表格的实际高度取决于文字字体大小等因素。

返回

Table - 插入的表格。

授权

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

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

insertTable(table)

在网页上插入所提供 Table 的副本。

插入的元素在此页面上的位置由源元素在其相应页面上的位置决定。

如果所提供的元素是从当前演示文稿中复制的占位符,则从母版页或布局页继承的属性也会在插入的元素上继承。

如果所提供的元素是从其他演示中复制的占位符,则从源演示中继承自母版页或布局页的属性会被复制到该元素中。

// Copy a table between presentations.
const otherPresentationSlide =
    SlidesApp.openById('presentationId').getSlides()[0];
const currentPresentationSlide =
    SlidesApp.getActivePresentation().getSlides()[0];
const table = otherPresentationSlide.getTables[0];
currentPresentationSlide.insertTable(
    table);  // Also available for Layout, Master, and Page.

参数

名称类型说明
tableTable要复制和插入的表格。

返回

Table - 插入的表格。

授权

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

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

insertTextBox(text)

在网页上插入一个包含所提供字符串的文本框 Shape

系统会在页面左上角插入默认大小的文本框形状。

// Insert text box with "Hello" on the first slide of presentation.
const slide = SlidesApp.getActivePresentation().getSlides()[0];
slide.insertTextBox('Hello');  // Also available for Layout, Master, and Page.

参数

名称类型说明
textString文本框形状应包含的字符串。

返回

Shape - 插入的文本框形状。

授权

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

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

insertTextBox(text, left, top, width, height)

在网页上插入一个包含所提供字符串的文本框 Shape

// Insert text box with "Hello" on the first slide of presentation. This text
// box is a square with a length of 10 points on each side.
const slide = SlidesApp.getActivePresentation().getSlides()[0];
slide.insertTextBox(
    'Hello', 0, 0, 10, 10);  // Also available for Layout, Master, and Page.

参数

名称类型说明
textString文本框形状应包含的字符串。
leftNumber文本框形状的水平位置,从页面左上角开始测量。
topNumber文本框形状的纵向位置,从页面左上角开始测量。
widthNumber文本框形状的宽度。
heightNumber文本框形状的高度。

返回

Shape - 插入的文本框形状。

授权

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

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

insertVideo(videoUrl)

在网页左上角插入一个默认大小的视频。

目前仅支持 YouTube 视频。

参数

名称类型说明
videoUrlString要插入的视频的网址。

返回

Video - 插入的视频。

授权

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

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

insertVideo(videoUrl, left, top, width, height)

在网页上插入具有指定位置和大小的视频。

目前仅支持 YouTube 视频。

参数

名称类型说明
videoUrlString要插入的视频的网址。
leftNumber视频的水平位置(以点为单位),从网页的左上角开始测量。
topNumber视频的垂直位置(以点为单位),从页面的左上角开始测量。
widthNumber视频的宽度(以点为单位)。
heightNumber视频的高度(以点为单位)。

返回

Video - 插入的视频。

授权

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

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

insertVideo(video)

在网页上插入所提供 Video 的副本。

插入的元素在此页面上的位置由源元素在其相应页面上的位置决定。

如果所提供的元素是从当前演示文稿中复制的占位符,则从母版页或布局页继承的属性也会在插入的元素上继承。

如果所提供的元素是从其他演示中复制的占位符,则从源演示中继承自母版页或布局页的属性会被复制到该元素中。

// Copy a video between presentations.
const otherPresentationSlide =
    SlidesApp.openById('presentationId').getSlides()[0];
const currentPresentationSlide =
    SlidesApp.getActivePresentation().getSlides()[0];
const video = otherPresentationSlide.getVideos[0];
currentPresentationSlide.insertVideo(
    video);  // Also available for Layout, Master, and Page.

参数

名称类型说明
videoVideo要复制和插入的视频。

返回

Video - 插入的视频。

授权

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

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

insertWordArt(wordArt)

在网页上插入所提供 WordArt 的副本。

插入的元素在此页面上的位置由源元素在其相应页面上的位置决定。

如果所提供的元素是从当前演示文稿中复制的占位符,则从母版页或布局页继承的属性也会在插入的元素上继承。

如果所提供的元素是从其他演示中复制的占位符,则从源演示中继承自母版页或布局页的属性会被复制到该元素中。

// Copy a word art between presentations.
const otherPresentationSlide =
    SlidesApp.openById('presentationId').getSlides()[0];
const currentPresentationSlide =
    SlidesApp.getActivePresentation().getSlides()[0];
const wordArt = otherPresentationSlide.getWordArts[0];

// Also available for Layout, Master, and Page.
currentPresentationSlide.insertWordArt(wordArt);

参数

名称类型说明
wordArtWordArt要复制和插入的群组。

返回

WordArt - 插入的艺术字。

授权

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

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

isSkipped()

返回相应幻灯片在演示模式下是否会被跳过。

返回

Boolean - 如果在演示模式下跳过幻灯片,则为 True

授权

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

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

move(index)

将幻灯片移动到指定索引。

参数

名称类型说明
indexInteger幻灯片应移至的索引,基于移动前的幻灯片排列顺序。该指数应介于 0 和演示文稿中的幻灯片数量之间(含首尾)。

授权

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

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

refreshSlide()

刷新幻灯片,以反映对链接的源幻灯片所做的任何更改。如果此幻灯片未关联,则返回而不进行任何更改。

如果链接的源幻灯片的相应母版和布局页面尚不存在,refreshSlide 方法会将它们复制到幻灯片的演示文稿中。如果这些数据源已存在,系统也会更新它们,以反映对来源所做的任何更改。

const currentPresentation = SlidesApp.getActivePresentation();
const sourcePresentation = SlidesApp.openById('sourcePresentationId');
const sourceSlide = sourcePresentation.getSlides()[0];
const linkedSlide = currentPresentation.append(
    sourceSlide,
    SlidesApp.SlideLinkingMode.LINKED,
);

sourceSlide.insertText(
    'hello world');  // Only the source slide has the text box.

linkedSlide.refreshSlide();  // The linked slide now has the text box.

抛出

Error - 如果不再具有对源演示的读取权限。

授权

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

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

remove()

移除相应页面。

授权

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

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

replaceAllText(findText, replaceText)

将与查找文本匹配的所有文本实例替换为替换文本。搜索不区分大小写。

参数

名称类型说明
findTextString要查找的文本。
replaceTextString用于替换匹配文本的文本。

返回

Integer - 更改后的出现次数

授权

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

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

replaceAllText(findText, replaceText, matchCase)

将与查找文本匹配的所有文本实例替换为替换文本。

参数

名称类型说明
findTextString要查找的文本。
replaceTextString用于替换匹配文本的文本。
matchCaseBoolean如果值为 true,则搜索区分大小写;如果值为 false,则搜索不区分大小写。

返回

Integer - 更改后的出现次数

授权

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

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

selectAsCurrentPage()

选择当前演示中的 Page 作为 current page selection,并移除任何之前的选择。

脚本只能访问运行该脚本的用户的选择内容,并且只有当脚本绑定到演示文稿时才能访问。

// Select the first slide as the current page selection and replace any previous
// selection.
const slide = SlidesApp.getActivePresentation().getSlides()[0];
slide.selectAsCurrentPage();  // Also available for Layout, Master, and Page.

授权

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

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

setSkipped(isSkipped)

设置在演示模式下是否跳过相应幻灯片。

参数

名称类型说明
isSkippedBooleanTrue 以在演示模式下跳过相应幻灯片。

授权

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

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

取消当前 Slide 与其来源幻灯片的关联。如果此幻灯片未关联,则返回而不进行任何更改。

const currentPresentation = SlidesApp.getActivePresentation();
const sourcePresentation = SlidesApp.openById('sourcePresentationId');
const sourceSlide = sourcePresentation.getSlides()[0];
const linkedSlide = currentPresentation.append(
    sourceSlide,
    SlidesApp.SlideLinkingMode.LINKED,
);

linkedSlide.unlink();

linkedSlide.getSourcePresentationId();  // returns null
linkedSlide.getSourceSlideObjectId();   // returns null
linkedSlide
    .getSlideLinkingMode();  // returns SlidesApp.SlideLinkingMode.NOT_LINKED

授权

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

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