一个 PageElement
,表示没有更具体分类的通用形状。包括文本框、矩形和其他预定义的形状。
方法
详细文档
alignOnPage(alignmentPosition)
使元素与页面上的指定对齐位置对齐。
参数
名称 | 类型 | 说明 |
---|---|---|
alignmentPosition | AlignmentPosition | 相应页面元素在页面上的对齐位置。 |
返回
Shape
- 此页面元素(用于串联)。
bringForward()
bringToFront()
duplicate()
复制页面元素。
复制的页面元素将位于与原始页面相同的位置。
返回
PageElement
- 此网页元素的新副本。
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
getAutofit()
getBorder()
getConnectionSites()
返回页面元素上的 ConnectionSite
列表;如果页面元素没有任何连接网站,则返回空列表。
返回
ConnectionSite[]
- 连接网站列表。如果此元素没有任何连接网站,此列表可能为空。
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
getContentAlignment()
返回形状中文本的 ContentAlignment
。
返回
ContentAlignment
- 表示文本在形状中的对齐方式。
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
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
getFill()
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()
返回元素围绕其中心顺时针旋转的角度(以度为单位),零度表示不旋转。
返回
Number
- 旋转角度,介于 0(含)和 360(不含)之间。
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
getShapeType()
getText()
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 | 要串联到此页面元素的转换上的转换。 |
返回
Shape
- 此页面元素(用于串联)。
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
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();
replaceWithImage(blobSource)
将此形状替换为 BlobSource
提供的图片。
系统会在插入时从提供的 BlobSource
提取一次图片,并存储其副本以供在演示文稿内显示。图片必须小于 50MB,不能超过 2500 万像素,并且必须采用 PNG、JPEG 或 GIF 格式。
为了保持图片的宽高比,图片会相对于现有形状的大小进行缩放和居中。
var shape = SlidesApp.getActivePresentation().getSlides()[0].getShapes()[0]; // Get the Drive image file with the given ID. var driveImage = DriveApp.getFileById(fileId); shape.replaceWithImage(driveImage);
参数
名称 | 类型 | 说明 |
---|---|---|
blobSource | BlobSource | 图片数据。 |
返回
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
replaceWithImage(blobSource, crop)
将此形状替换为 BlobSource
提供的图片。
插入图片后,系统会从 BlobSource
提取该图片一次,并会存储其副本以供在演示文稿内显示。图片必须小于 50MB,不能超过 2500 万像素,并且必须采用 PNG、JPEG 或 GIF 格式。
var shape = SlidesApp.getActivePresentation().getSlides()[0].getShapes()[0]; // Get the Drive image file with the given ID. var driveImage = DriveApp.getFileById(fileId); // Replace and crop the replaced image. shape.replaceWithImage(driveImage, true);
参数
名称 | 类型 | 说明 |
---|---|---|
blobSource | BlobSource | 图片数据。 |
crop | Boolean | 如果为 true ,则裁剪图片以适合现有形状的大小。否则,图片会缩放并居中。 |
返回
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
replaceWithImage(imageUrl)
将此形状替换为图片。
插入图片后,系统会从网址中抓取一次图片,并存储副本以将其显示在演示文稿中。图片必须小于 50MB,不能超过 2500 万像素,并且必须采用 PNG、JPEG 或 GIF 格式。
提供的网址必须可以公开访问,并且大小不得超过 2kB。网址本身会随图片一起保存,并通过 Image.getSourceUrl()
公开。
为了保持图片的宽高比,图片会相对于现有形状的大小进行缩放和居中。
参数
名称 | 类型 | 说明 |
---|---|---|
imageUrl | String | 作为图片下载来源的图片网址。 |
返回
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
replaceWithImage(imageUrl, crop)
将此形状替换为图片。
插入图片后,系统会从网址中抓取一次图片,并存储副本以将其显示在演示文稿中。图片必须小于 50MB,不能超过 2500 万像素,并且必须采用 PNG、JPEG 或 GIF 格式。
提供的网址不得超过 2kB。网址本身会与图片一起保存,并通过 Image.getSourceUrl()
公开。
参数
名称 | 类型 | 说明 |
---|---|---|
imageUrl | String | 作为图片下载来源的图片网址。 |
crop | Boolean | 如果为 true ,则裁剪图片以适合现有形状的大小。否则,图片会缩放并居中。 |
返回
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
replaceWithSheetsChart(sourceChart)
将此形状替换为 Google 表格图表。
图表会与源 Google 表格图表相关联,以便更新图表。其他协作者可以看到指向源电子表格的链接。
var sheet = SpreadsheetApp.openById('spreadsheetId').getSheets()[0]; var chart = sheet.getCharts()[0]; // Replace the shape with the Sheets chart. var shape = SlidesApp.getActivePresentation().getSlides()[0].getShapes()[0]; shape.replaceWithSheetsChart(chart);
参数
名称 | 类型 | 说明 |
---|---|---|
sourceChart | EmbeddedChart | 电子表格中用于替换形状的图表。 |
返回
SheetsChart
- 替换形状的图表。
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
replaceWithSheetsChartAsImage(sourceChart)
将此形状替换为 Google 表格图表的图片。
为了保持 Google 表格图表的宽高比,图表图片会根据现有形状的大小进行缩放和居中显示。
图表的图片未与 Google 表格源图表相关联。
var sheet = SpreadsheetApp.openById('spreadsheetId').getSheets()[0]; var chart = sheet.getCharts()[0]; // Replace the shape with the Sheets chart as an image. var shape = SlidesApp.getActivePresentation().getSlides()[0].getShapes()[0]; shape.replaceWithSheetsChartAsImage(chart);
参数
名称 | 类型 | 说明 |
---|---|---|
sourceChart | EmbeddedChart | 电子表格中用于替换形状的图表。 |
返回
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()
setContentAlignment(contentAlignment)
设置形状中文本的 ContentAlignment
。
此方法会自动在更新后的形状上停用文本自动调整属性。
参数
名称 | 类型 | 说明 |
---|---|---|
contentAlignment | ContentAlignment | 要设置的对齐方式。 |
返回
Shape
- 此形状,用于链。
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
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 | 要设置替代文本说明的字符串。 |
返回
Shape
- 此页面元素。
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
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)
根据幻灯片的相对位置将 Link
设置为指定的 Slide
。
// 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 | 要设置替代文本标题的字符串。 |
返回
Shape
- 此页面元素。
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations
setTop(top)
setTransform(transform)
使用提供的转换设置页面元素的转换。
更新组的转换会更改该组中页面元素的绝对转换,从而改变其外观。
更新某个组内的页面元素转换仅会更改该页面元素的转换,而不会影响组或其他组元素的转换。
如需详细了解转换如何影响页面元素的视觉外观,请参阅 getTransform()
。
参数
名称 | 类型 | 说明 |
---|---|---|
transform | AffineTransform | 为此页面元素设置的转换。 |
返回
Shape
- 此元素,用于实现链式处理。
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/presentations.currentonly
-
https://www.googleapis.com/auth/presentations