表示图片的 PageElement。
方法
| 方法 | 返回类型 | 简介 |
|---|---|---|
align | Image | 将元素与页面上的指定对齐位置对齐。 |
bring | Image | 将页面元素在页面上向前移动一个元素。 |
bring | Image | 将页面元素置于页面最前面。 |
duplicate() | Page | 复制页面元素。 |
get | Blob | 以转换为指定内容类型的 blob 形式返回此对象内的数据。 |
get | Blob | 以 blob 形式返回此图片中的数据。 |
get | Border | 返回图片的 Border。 |
get | Connection | 返回页面元素上的 Connection 列表;如果页面元素没有任何连接点,则返回空列表。 |
get | String | 获取图片网址。 |
get | String | 返回网页元素的替代文本说明。 |
get | Number|null | 获取元素的高度(以磅为单位),即元素未旋转时其边界框的高度。 |
get | Number|null | 返回元素的固有高度(以点为单位)。 |
get | Number|null | 返回元素的固有宽度(以点为单位)。 |
get | Number | 返回元素在页面中的水平位置(以点为单位),当元素未旋转时,该位置从页面的左上角开始测量。 |
get | Link|null | 如果没有链接,则返回 Link 或 null。 |
get | String | 返回相应对象的唯一 ID。 |
get | Page | 返回网页元素的类型,以 Page 枚举表示。 |
get | Group|null | 返回相应页面元素所属的组;如果该元素不属于任何组,则返回 null。 |
get | Page | 返回相应页面元素所在的页面。 |
get | Page | 返回占位符的父页面元素。 |
get | Integer|null | 返回占位图片对应的索引。 |
get | Placeholder | 返回图片的占位符类型;如果形状不是占位符,则返回 Placeholder。 |
get | Number | 返回元素围绕其中心顺时针旋转的角度(以度为单位),其中零度表示不旋转。 |
get | String|null | 获取图片的来源网址(如果有)。 |
get | String | 返回网页元素的替代文本标题。 |
get | Number | 获取元素的垂直位置(以点为单位),该位置是从页面左上角测量的,前提是元素未旋转。 |
get | Affine | 返回页面元素的转换。 |
get | Number|null | 返回元素的宽度(以点为单位),即元素未旋转时其边界框的宽度。 |
preconcatenate | Image | 将提供的转换预串联到页面元素的现有转换。 |
remove() | void | 移除页面元素。 |
remove | void | 移除 Link。 |
replace(blobSource) | Image | 将此图片替换为 Blob 对象描述的图片。 |
replace(blobSource, crop) | Image | 将此图片替换为 Image 对象描述的图片,并可选择裁剪图片以适应。 |
replace(imageUrl) | Image | 将此图片替换为从所提供网址下载的另一张图片。 |
replace(imageUrl, crop) | Image | 使用从所提供网址下载的另一张图片替换此图片,并可选择裁剪图片以适应大小。 |
scale | Image | 按指定比例缩放元素的高度。 |
scale | Image | 按指定比例缩放元素的宽度。 |
select() | void | 仅选择当前演示中的 Page,并移除任何之前的选择。 |
select(replace) | void | 选择当前演示文稿中的 Page。 |
send | Image | 将页面元素在页面上向后移动一个元素。 |
send | Image | 将页面元素发送到页面后方。 |
set | Image | 设置网页元素的替代文本说明。 |
set | Image | 以磅为单位设置元素的高度,即元素未旋转时元素边界框的高度。 |
set | Image | 设置元素在页面中的水平位置(以点为单位),从页面左上角开始测量(当元素未旋转时)。 |
set | Link | 使用幻灯片的从零开始的索引,将 Link 设置为给定的 Slide。 |
set | Link | 将 Link 设置为给定的 Slide,链接由给定的幻灯片 ID 设置。 |
set | Link | 使用幻灯片的相对位置,将 Link 设置为给定的 Slide。 |
set | Link | 将 Link 设置为给定的非空网址字符串。 |
set | Image | 设置元素围绕其中心顺时针旋转的角度(以度为单位)。 |
set | Image | 设置网页元素的替代文本标题。 |
set | Image | 设置元素的垂直位置(以点为单位),当元素未旋转时,该位置从页面的左上角开始测量。 |
set | Image | 使用提供的转换设置页面元素的转换。 |
set | Image | 以磅为单位设置元素的宽度,即元素未旋转时,元素边界框的宽度。 |
详细文档
alignOnPage(alignmentPosition)
将元素与页面上的指定对齐位置对齐。
参数
| 名称 | 类型 | 说明 |
|---|---|---|
alignment | Alignment | 相应页面元素在页面上的对齐位置。 |
返回
Image - 此页面元素,用于链式调用。
bringForward()
bringToFront()
duplicate()
复制页面元素。
复制的页面元素放置在与原始元素相同的页面和位置。
返回
PageElement -相应页面元素的新副本。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getAs(contentType)
getBlob()
getBorder()
getConnectionSites()
返回页面元素上的 ConnectionSite 列表;如果页面元素没有任何连接点,则返回空列表。
返回
ConnectionSite[] - 连接网站列表,如果此元素没有连接网站,则可能为空。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getContentUrl()
获取指向图片的网址。
此网址会标记请求者的账号,因此拥有此网址的任何人都可以有效访问图片,就像原始请求者一样。如果演示文稿的共享设置发生变化,您可能无法再访问相应图片。返回的网址会在短时间后过期。
返回
String
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getDescription()
返回网页元素的替代文本说明。说明与标题结合使用,以显示和朗读替代文本。
返回
String - 页面元素的替代文本说明。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getHeight()
getInherentHeight()
返回元素的固有高度(以点为单位)。
页面元素的转换是相对于其固有大小而言的。使用固有大小并结合元素的转换来确定元素的最终视觉外观。
返回
Number|null - 页面元素的固有高度(以点为单位),如果页面元素没有高度,则为 null。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getInherentWidth()
返回元素的固有宽度(以点为单位)。
页面元素的转换是相对于其固有大小而言的。使用固有大小并结合元素的转换来确定元素的最终视觉外观。
返回
Number|null - 页面元素的固有宽度(以点为单位),如果页面元素没有宽度,则为 null。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getLeft()
返回元素在页面中的水平位置(以点为单位),当元素未旋转时,该位置从页面的左上角开始测量。
返回
Number - 相应元素在页面上的水平位置(以点为单位),从页面左上角开始计算。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getLink()
如果不存在链接,则返回 Link 或 null。
const shape = SlidesApp.getActivePresentation().getSlides()[0].getShapes()[0]; const link = shape.getLink(); if (link != null) { Logger.log(`Shape has a link of type: ${link.getLinkType()}`); }
返回
Link|null - 如果没有链接,则为 Link 或 null。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getObjectId()
返回相应对象的唯一 ID。网页和网页元素使用的对象 ID 共享同一命名空间。
返回
String - 相应对象的唯一 ID。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getPageElementType()
返回网页元素的类型,以 PageElementType 枚举表示。
返回
PageElementType - 页面元素的类型。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getParentGroup()
getParentPage()
getParentPlaceholder()
返回占位符的父页面元素。如果图片不是占位图片或没有父级,则返回 null。
返回
PageElement|null - 此图片占位位符的父页面元素;如果此图片不是占位位符或没有父元素,则返回 null。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getPlaceholderIndex()
返回占位图片对应的索引。如果同一网页上的两个或更多占位图片属于同一类型,则它们各自具有唯一的索引值。如果图片不是占位符,则返回 null。
返回
Integer|null - 此图片的占位索引,如果图片不是占位图片,则为 null。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getPlaceholderType()
返回图片的占位符类型;如果形状不是占位符,则返回 PlaceholderType.NONE。
返回
PlaceholderType - 此图片的占位符类型。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getRotation()
返回元素围绕其中心顺时针旋转的角度(以度为单位),其中零度表示不旋转。
返回
Number - 旋转角度(以度为单位),介于 0(含)和 360(不含)之间。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getSourceUrl()
获取图片的来源网址(如果有)。
当通过网址插入图片时,返回图片插入期间提供的网址。
返回
String|null - 图片网址,如果图片没有来源网址,则为 null。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getTitle()
返回网页元素的替代文本标题。标题与说明结合使用,以显示和朗读替代文本。
返回
String - 网页元素的替代文本标题。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getTop()
获取元素的垂直位置(以点为单位),该位置是从页面左上角测量的,前提是元素未旋转。
返回
Number - 相应元素在页面上的垂直位置(以点为单位),从页面左上角开始计算。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getTransform()
返回页面元素的转换。
页面元素的视觉外观由其绝对转换决定。若要计算绝对转换,请将页面元素的转换与所有父组的转换预先串联起来。如果页面元素不在群组中,则其绝对转换与此字段中的值相同。
返回
AffineTransform - 网页元素的转换。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
getWidth()
preconcatenateTransform(transform)
将提供的转换预串联到页面元素的现有转换。
newTransform = argument * existingTransform;
例如,如需将页面元素向左移动 36 点,请执行以下操作:
const element = SlidesApp.getActivePresentation().getSlides()[0].getPageElements()[0]; element.preconcatenateTransform( SlidesApp.newAffineTransformBuilder().setTranslateX(-36.0).build(), );
您还可以将网页元素的转换替换为 setTransform(transform)。
参数
| 名称 | 类型 | 说明 |
|---|---|---|
transform | Affine | 要预先串联到此页面元素的转换的转换。 |
返回
Image - 此页面元素,用于链式调用。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
remove()
移除页面元素。
如果移除操作后,Group 仅包含一个或不包含任何页面元素,则该组本身也会被移除。
如果主布局或布局中移除了占位符 PageElement,则所有继承的空占位符也会一并移除。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
removeLink()
移除 Link。
const slides = SlidesApp.getActivePresentation().getSlides(); slides[1].getShapes()[0].removeLink();
replace(blobSource)
将此图片替换为 BlobSource 对象描述的图片。
插入图片时,系统会从
BlobSource 中提取图片一次,并存储一份副本以在演示文稿中显示。
图片大小必须小于 50MB,像素数不得超过 2500 万,且必须为 PNG、JPEG 或 GIF 格式。
为了保持图片的宽高比,系统会根据现有图片的大小对图片进行缩放和居中。
const image = SlidesApp.getActivePresentation().getSlides()[0].getImages()[0]; // Get the Drive image file with the given ID. const driveImage = DriveApp.getFileById("123abc"); image.replace(driveImage);
参数
| 名称 | 类型 | 说明 |
|---|---|---|
blob | Blob | 图片数据。 |
返回
Image - 更换后的 Image。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
replace(blobSource, crop)
将此图片替换为 Image 对象描述的图片,并可选择裁剪图片以适应。
插入图片时,系统会从
BlobSource 中提取图片一次,并存储一份副本以在演示文稿中显示。
图片大小必须小于 50MB,像素数不得超过 2500 万,且必须为 PNG、JPEG 或 GIF 格式。
const image = SlidesApp.getActivePresentation().getSlides()[0].getImages()[0]; // Get the Drive image file with the given ID. const driveImage = DriveApp.getFileById('123abc'); // Replace and crop the drive image. image.replace(driveImage, true);
参数
| 名称 | 类型 | 说明 |
|---|---|---|
blob | Blob | 图片数据。 |
crop | Boolean | 如果值为 true,则裁剪图片以适应现有图片的大小。否则,系统会对图片进行缩放和居中处理。 |
返回
Image - 更换后的 Image。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
replace(imageUrl)
将此图片替换为从所提供网址下载的另一张图片。
插入图片时,系统会从相应网址获取图片一次,并存储一份副本以在演示中显示。图片大小不得超过 50MB,像素数不得超过 2500 万,且必须为 PNG、JPEG 或 GIF 格式。
所提供的网址必须可以公开访问,且大小不得超过 2kB。网址本身会与图片一起保存,并通过 getSourceUrl() 公开。
为了保持图片的宽高比,系统会根据现有图片的大小对图片进行缩放和居中处理。
参数
| 名称 | 类型 | 说明 |
|---|---|---|
image | String | 用于下载图片的网址。 |
返回
Image - 更换后的 Image。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
replace(imageUrl, crop)
使用从提供的网址下载的另一张图片替换此图片,并可选择裁剪图片以适应。
插入图片时,系统会从相应网址获取图片一次,并存储一份副本以在演示中显示。图片大小不得超过 50MB,像素数不得超过 2500 万,且必须为 PNG、JPEG 或 GIF 格式。
所提供的网址不得大于 2kB。
参数
| 名称 | 类型 | 说明 |
|---|---|---|
image | String | 用于下载图片的网址。 |
crop | Boolean | 如果值为 true,则裁剪图片以适应现有图片的大小。否则,系统会对图片进行缩放和居中处理。 |
返回
Image - 更换后的 Image。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
scaleHeight(ratio)
scaleWidth(ratio)
select()
仅选择当前演示中的 PageElement,并移除任何之前的选择。这与使用 true 调用 select(replace) 相同。
脚本只能访问运行该脚本的用户的选择内容,并且只有当脚本绑定到演示文稿时才能访问。
这会将 PageElement 的父 Page 设置为 current page selection。
const slide = SlidesApp.getActivePresentation().getSlides()[0]; const pageElement = slide.getPageElements()[0]; // Only select this page element and replace any previous selection. pageElement.select();
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
select(replace)
选择当前演示文稿中的 PageElement。
脚本只能访问运行该脚本的用户的选择内容,并且只有当脚本绑定到演示文稿时才能访问。
将 true 传递给此方法,以仅选择 PageElement 并移除任何之前的选择。这还会将 PageElement 的父 Page 设置为 current page selection。
传递 false 以选择多个 PageElement 对象。PageElement 对象必须位于同一 Page 中。
使用 false 参数选择页面元素时,必须满足以下条件:
PageElement对象的父级Page必须是current page selection。- 不应选择多个
Page对象。
为确保这种情况,首选方法是先使用 Page.selectAsCurrentPage() 选择父级 Page,然后选择该页面中的页面元素。
const slide = SlidesApp.getActivePresentation().getSlides()[0]; // First select the slide page, as the current page selection. slide.selectAsCurrentPage(); // Then select all the page elements in the selected slide page. const pageElements = slide.getPageElements(); for (let i = 0; i < pageElements.length; i++) { pageElements[i].select(false); }
参数
| 名称 | 类型 | 说明 |
|---|---|---|
replace | Boolean | 如果值为 true,则选择会替换任何先前的选择;否则,选择会添加到任何先前的选择中。 |
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
sendBackward()
sendToBack()
setDescription(description)
设置网页元素的替代文本说明。
该方法不支持 Group 元素。
// Set the first page element's alt text description to "new alt text // description". const pageElement = SlidesApp.getActivePresentation().getSlides()[0].getPageElements()[0]; pageElement.setDescription('new alt text description'); Logger.log(pageElement.getDescription());
参数
| 名称 | 类型 | 说明 |
|---|---|---|
description | String | 用于设置替代文本说明的字符串。 |
返回
Image - 此页面元素。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
setHeight(height)
setLeft(left)
setLinkSlide(slideIndex)
使用幻灯片的从零开始的索引,将 Link 设置为给定的 Slide。
// Set a link to the first slide of the presentation. const slides = SlidesApp.getActivePresentation().getSlides(); const shape = slides[1].getShapes()[0]; const link = shape.setLinkSlide(0);
参数
| 名称 | 类型 | 说明 |
|---|---|---|
slide | Integer | 幻灯片的索引(从零开始)。 |
返回
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
setLinkSlide(slide)
将 Link 设置为给定的 Slide,链接由给定的幻灯片 ID 设置。
// Set a link to the first slide of the presentation. const slides = SlidesApp.getActivePresentation().getSlides(); const shape = slides[1].getShapes()[0]; const link = shape.setLinkSlide(slides[0]);
参数
| 名称 | 类型 | 说明 |
|---|---|---|
slide | Slide | 要关联的 Slide。 |
返回
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
setLinkSlide(slidePosition)
使用幻灯片的相对位置,将 Link 设置为给定的 Slide。
// Set a link to the first slide of the presentation. const slides = SlidesApp.getActivePresentation().getSlides(); const shape = slides[1].getShapes()[0]; const link = shape.setLinkSlide(SlidesApp.SlidePosition.FIRST_SLIDE);
参数
| 名称 | 类型 | 说明 |
|---|---|---|
slide | Slide | 相对 Slide。 |
返回
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
setLinkUrl(url)
将 Link 设置为给定的非空网址字符串。
// Set a link to the URL. const slides = SlidesApp.getActivePresentation().getSlides(); const shape = slides[1].getShapes()[0]; const link = shape.setLinkUrl('https://slides.google.com');
参数
| 名称 | 类型 | 说明 |
|---|---|---|
url | String | 网址字符串。 |
返回
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
setRotation(angle)
setTitle(title)
设置网页元素的替代文本标题。
该方法不支持 Group 元素。
// Set the first page element's alt text title to "new alt text title". const pageElement = SlidesApp.getActivePresentation().getSlides()[0].getPageElements()[0]; pageElement.setTitle('new alt text title'); Logger.log(pageElement.getTitle());
参数
| 名称 | 类型 | 说明 |
|---|---|---|
title | String | 用于设置替代文本标题的字符串。 |
返回
Image - 此页面元素。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations
setTop(top)
setTransform(transform)
使用提供的转换设置页面元素的转换。
更新组的转换会更改该组中页面元素的绝对转换,从而改变其视觉外观。
更新组中某个页面元素的转换只会更改该页面元素的转换,而不会影响组或组中其他页面元素的转换。
如需详细了解转换如何影响网页元素的视觉外观,请参阅 getTransform()。
参数
| 名称 | 类型 | 说明 |
|---|---|---|
transform | Affine | 为相应页面元素设置的转换。 |
返回
Image - 此元素,用于链式调用。
授权
使用此方法的脚本需要获得以下一项或多项范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly -
https://www.googleapis.com/auth/presentations