表示图片的 PageElement
。
方法
方法 | 返回类型 | 简介 |
---|---|---|
alignOnPage(alignmentPosition) | Image | 将元素与页面上的指定对齐位置对齐。 |
bringForward() | Image | 将页面上的页面元素前移一个元素。 |
bringToFront() | Image | 将页面元素移到页面的前面。 |
duplicate() | PageElement | 复制页面元素。 |
getAs(contentType) | Blob | 返回此对象内的数据,并将其作为 blob 转换为指定内容类型。 |
getBlob() | Blob | 以 blob 的形式返回此图像中的数据。 |
getBorder() | Border | 返回图片的 Border 。 |
getConnectionSites() | ConnectionSite[] | 返回页面元素上的 ConnectionSite 列表;如果页面元素没有任何连接站点,则返回空列表。 |
getContentUrl() | String | 获取图片的网址。 |
getDescription() | String | 返回页面元素的替代文本说明。 |
getHeight() | Number | 获取元素的高度(以点为单位),这是元素在没有旋转时,元素边界框的高度。 |
getInherentHeight() | Number | 返回元素的固有高度(以点为单位)。 |
getInherentWidth() | Number | 返回元素的固有宽度(以点为单位)。 |
getLeft() | Number | 返回元素的水平位置(以点为单位),当元素没有旋转时,从页面左上角开始测量。 |
getLink() | Link | 如果没有链接,则返回 Link 或 null 。 |
getObjectId() | String | 返回此对象的唯一 ID。 |
getPageElementType() | PageElementType | 返回页面元素的类型,表示为 PageElementType 枚举。 |
getParentGroup() | Group | 返回此网页元素所属的群组,如果该元素不在任何群组中,则返回 null 。 |
getParentPage() | Page | 返回此页面元素所在的页面。 |
getParentPlaceholder() | PageElement | 返回占位符的父页面元素。 |
getPlaceholderIndex() | Integer | 返回占位符图片的索引。 |
getPlaceholderType() | PlaceholderType | 返回图片的占位符类型,如果形状不是占位符,则返回 PlaceholderType.NONE 。 |
getRotation() | Number | 返回元素围绕其中心的顺时针旋转角度(以度为单位),其中 0 度表示不旋转。 |
getSourceUrl() | String | 获取图片的来源网址(如果有)。 |
getTitle() | String | 返回页面元素的替代文本标题。 |
getTop() | Number | 获取元素的垂直位置(以点为单位),当元素没有旋转时,从页面左上角开始测量。 |
getTransform() | AffineTransform | 返回页面元素的转换。 |
getWidth() | Number | 返回元素的宽度(以点为单位),这是元素在没有旋转时,其边界框的宽度。 |
preconcatenateTransform(transform) | Image | 将提供的转换与页面元素的现有转换预串联。 |
remove() | void | 移除页面元素。 |
removeLink() | void | 移除 Link 。 |
replace(blobSource) | Image | 将此图片替换为 BlobSource 对象描述的图片。 |
replace(blobSource, crop) | Image | 将此图片替换为 Image 对象描述的图片,可以选择性地剪裁图片以适应大小。 |
replace(imageUrl) | Image | 将此图片替换为从提供的网址下载的其他图片。 |
replace(imageUrl, crop) | Image | 将此图片替换为从提供的网址下载的其他图片,可以选择将图片剪裁为合适的尺寸。 |
scaleHeight(ratio) | Image | 按指定的比率缩放元素的高度。 |
scaleWidth(ratio) | Image | 按指定的比率缩放元素的宽度。 |
select() | void | 仅选择当前演示中的 PageElement ,并移除之前的所有选择。 |
select(replace) | void | 在当前演示文稿中选择 PageElement 。 |
sendBackward() | Image | 将页面上的页面元素向后移动一个元素。 |
sendToBack() | Image | 将页面元素发送到页面的背面。 |
setDescription(description) | Image | 设置页面元素的替代文本说明。 |
setHeight(height) | Image | 设置元素的高度(以点为单位),这是元素没有旋转时元素边界框的高度。 |
setLeft(left) | Image | 设置元素的水平位置(以点为单位),当元素没有旋转时,从页面左上角开始测量。 |
setLinkSlide(slideIndex) | Link | 使用幻灯片索引(从零开始)将 Link 设为指定的 Slide 。 |
setLinkSlide(slide) | Link | 将 Link 设为指定的 Slide ,链接由指定的幻灯片 ID 设置。 |
setLinkSlide(slidePosition) | Link | 使用幻灯片的相对位置将 Link 设为指定的 Slide 。 |
setLinkUrl(url) | Link | 将 Link 设置为指定的非空网址字符串。 |
setRotation(angle) | Image | 设置元素围绕其中心的顺时针旋转角度(以度为单位)。 |
setTitle(title) | Image | 设置页面元素的替代文本标题。 |
setTop(top) | Image | 设置元素的垂直位置(以点为单位),当元素没有旋转时,从页面左上角开始测量。 |
setTransform(transform) | Image | 使用提供的转换设置页面元素的转换。 |
setWidth(width) | Image | 设置元素的宽度(以点为单位),这是元素在没有旋转时元素边界框的宽度。 |
详细文档
alignOnPage(alignmentPosition)
将元素与页面上的指定对齐位置对齐。
参数
名称 | 类型 | 说明 |
---|---|---|
alignmentPosition | AlignmentPosition | 此网页元素在页面上的对齐位置。 |
弃踢回攻
Image
- 此页面元素,用于链接。
bringForward()
bringToFront()
duplicate()
复制页面元素。
复制的页面元素会放置在与原始网页相同的页面上。
弃踢回攻
PageElement
- 此网页元素的新副本。
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
getAs(contentType)
返回此对象内的数据,并将其作为 blob 转换为指定内容类型。此方法会为文件名添加适当的扩展名,例如“myfile.pdf”。不过,它假设最后一个英文句点后面的文件名部分(如果有)是应该替换的现有扩展名。因此,“ShoppingList.12.25.2014”将变为“ShoppingList.12.25.pdf”。
如需查看转化次数的每日配额,请参阅 Google 服务的配额。新创建的 Google Workspace 网域可能会暂时受到更严格的配额限制。
参数
名称 | 类型 | 说明 |
---|---|---|
contentType | String | 要转换为的 MIME 类型。对于大多数 blob,'application/pdf' 是唯一有效的选项。对于 BMP、GIF、JPEG 或 PNG 格式的图片,'image/bmp' 、'image/gif' 、'image/jpeg' 或 'image/png' 中的任何一个也都有效。 |
弃踢回攻
Blob
- 作为 blob 的数据。
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
。
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
getInherentWidth()
返回元素的固有宽度(以点为单位)。
页面元素的转换与其固有大小相关。将固有尺寸与元素的转换结合使用来确定元素的最终视觉外观。
弃踢回攻
Number
- 页面元素的固有宽度(以点为单位),如果页面元素没有宽度,则为 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()
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
。
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
getPlaceholderIndex()
返回占位符图片的索引。如果同一网页上的两张或更多占位符图片属于同一类型,则它们各自具有唯一的索引值。如果图片不是占位符,则返回 null
。
弃踢回攻
Integer
- 此图片的占位符索引,如果图片不是占位符,则为 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()
返回元素围绕其中心的顺时针旋转角度(以度为单位),其中 0 度表示不旋转。
弃踢回攻
Number
- 旋转角度,以 0(含)到 360(不含)之间的度为单位。
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
getSourceUrl()
获取图片的来源网址(如果有)。
通过网址插入图片时,会返回在插入图片期间提供的网址。
弃踢回攻
String
- 图片网址,如果图片没有来源网址,则为 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 个点,请执行以下操作:
element.preconcatenateTransform(SlidesApp.newAffineTransformBuilder() .setTranslateX(-36.0) .build());
您还可以将页面元素的转换替换为 setTransform(transform)
。
参数
名称 | 类型 | 说明 |
---|---|---|
transform | AffineTransform | 要预串联到此页面元素的转换的转换。 |
弃踢回攻
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
。
shape.removeLink();
replace(blobSource)
将此图片替换为 BlobSource
对象描述的图片。
插入图片会从
BlobSource
中提取一次图片,并存储副本以便在演示文稿中显示。图片必须小于 50MB,不能超过 2500 万像素,并且必须为 PNG、JPEG 或 GIF 格式。
为了保持图片的宽高比,系统会根据现有图片的尺寸缩放并居中图片。
var image = SlidesApp.getActivePresentation().getSlides()[0].getImages()[0]; // Get the Drive image file with the given ID. var driveImage = DriveApp.getFileById(fileId); image.replace(driveImage);
参数
名称 | 类型 | 说明 |
---|---|---|
blobSource | BlobSource | 图片数据。 |
弃踢回攻
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 格式。
var image = SlidesApp.getActivePresentation().getSlides()[0].getImages()[0]; // Get the Drive image file with the given ID. var driveImage = DriveApp.getFileById(fileId); // Replace and crop the drive image. image.replace(driveImage, true);
参数
名称 | 类型 | 说明 |
---|---|---|
blobSource | BlobSource | 图片数据。 |
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()
公开。
为了保持图片的宽高比,系统会根据现有图片的尺寸缩放并居中图片。
参数
名称 | 类型 | 说明 |
---|---|---|
imageUrl | 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。
参数
名称 | 类型 | 说明 |
---|---|---|
imageUrl | 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
。
var slide = SlidesApp.getActivePresentation().getSlides()[0]; var 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
,然后选择该页面中的页面元素。
var 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. var pageElements = slide.getPageElements(); for (var 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". var 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)
setLinkSlide(slide)
将 Link
设为指定的 Slide
,链接由指定的幻灯片 ID 设置。
// Set a link to the first slide of the presentation. var slide = presentation.getSlides()[0]; shape.setLinkSlide(slide);
参数
名称 | 类型 | 说明 |
---|---|---|
slide | Slide | 要关联的 Slide 。 |
弃踢回攻
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
setLinkSlide(slidePosition)
// Set a link to the first slide of the presentation. shape.setLinkSlide(SlideApp.SlidePosition.FIRST_SLIDE);
参数
名称 | 类型 | 说明 |
---|---|---|
slidePosition | SlidePosition | 相对 SlidePosition 。 |
弃踢回攻
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
setLinkUrl(url)
setRotation(angle)
setTitle(title)
设置页面元素的替代文本标题。
Group
元素不支持此方法。
// Set the first page element's alt text title to "new alt text title". var 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 | AffineTransform | 为此页面元素设置的转换。 |
弃踢回攻
Image
- 此元素,用于链接。
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations