Class Shape

形状

表示没有更具体分类的通用形状的 PageElement。包括文本框、矩形和其他预定义形状。

方法

方法返回类型简介
alignOnPage(alignmentPosition)Shape将元素与页面上的指定对齐位置对齐。
bringForward()Shape将页面元素在页面上向前移动一个元素。
bringToFront()Shape将页面元素置于页面最前面。
duplicate()PageElement复制页面元素。
getAutofit()Autofit|null返回相应形状内文本的 Autofit
getBorder()Border返回形状的 Border
getConnectionSites()ConnectionSite[]返回页面元素上的 ConnectionSite 列表;如果页面元素没有任何连接点,则返回空列表。
getContentAlignment()ContentAlignment返回形状中文字的 ContentAlignment
getDescription()String返回网页元素的替代文本说明。
getFill()Fill返回形状的 Fill
getHeight()Number|null获取元素的高度(以磅为单位),即元素未旋转时其边界框的高度。
getInherentHeight()Number|null返回元素的固有高度(以点为单位)。
getInherentWidth()Number|null返回元素的固有宽度(以点为单位)。
getLeft()Number返回元素在页面中的水平位置(以点为单位),当元素未旋转时,该位置从页面的左上角开始测量。
getLink()Link|null如果没有链接,则返回 Linknull
getObjectId()String返回相应对象的唯一 ID。
getPageElementType()PageElementType返回网页元素的类型,以 PageElementType 枚举表示。
getParentGroup()Group|null返回相应网页元素所属的组;如果该元素不属于任何组,则返回 null
getParentPage()Page返回相应页面元素所在的页面。
getParentPlaceholder()PageElement|null返回占位符的父网页元素。
getPlaceholderIndex()Integer|null返回形状的占位索引。
getPlaceholderType()PlaceholderType返回形状的占位符类型;如果形状不是占位符,则返回 PlaceholderType.NONE
getRotation()Number返回元素围绕其中心顺时针旋转的角度(以度为单位),其中零度表示不旋转。
getShapeType()ShapeType返回形状的类型。
getText()TextRange返回形状的文本内容。
getTitle()String返回网页元素的替代文本标题。
getTop()Number获取元素在页面中的垂直位置(以点为单位),该位置是从元素的左上角测量的(当元素未旋转时)。
getTransform()AffineTransform返回页面元素的转换。
getWidth()Number|null返回元素的宽度(以磅为单位),即元素未旋转时其边界框的宽度。
preconcatenateTransform(transform)Shape将提供的转换预串联到网页元素的现有转换。
remove()void移除页面元素。
removeLink()void移除 Link
replaceWithImage(blobSource)Image将此形状替换为 BlobSource 提供的图片。
replaceWithImage(blobSource, crop)Image将此形状替换为 BlobSource 提供的图片。
replaceWithImage(imageUrl)Image将此形状替换为图片。
replaceWithImage(imageUrl, crop)Image将此形状替换为图片。
replaceWithSheetsChart(sourceChart)SheetsChart将此形状替换为 Google 表格图表。
replaceWithSheetsChartAsImage(sourceChart)Image将此形状替换为 Google 表格图表的图片。
scaleHeight(ratio)Shape按指定比例缩放元素的高度。
scaleWidth(ratio)Shape按指定比例缩放元素的宽度。
select()void仅选择有效演示中的 PageElement,并移除任何之前的选择。
select(replace)void选择有效演示中的 PageElement
sendBackward()Shape将页面元素在页面上向后移动一个元素。
sendToBack()Shape将页面元素移至页面底部。
setContentAlignment(contentAlignment)Shape设置形状中文字的 ContentAlignment
setDescription(description)Shape设置网页元素的替代文本说明。
setHeight(height)Shape以磅为单位设置元素的高度,即元素未旋转时元素边界框的高度。
setLeft(left)Shape设置元素在页面中的水平位置(以点为单位),该位置从元素的左上角开始测量(当元素未旋转时)。
setLinkSlide(slideIndex)Link使用幻灯片的从零开始的索引,将 Link 设置为给定的 Slide
setLinkSlide(slide)LinkLink 设置为给定的 Slide,链接由给定的幻灯片 ID 设置。
setLinkSlide(slidePosition)Link使用幻灯片的相对位置,将 Link 设置为给定的 Slide
setLinkUrl(url)LinkLink 设置为给定的非空网址字符串。
setRotation(angle)Shape设置元素围绕其中心顺时针旋转的角度(以度为单位)。
setTitle(title)Shape设置网页元素的替代文本标题。
setTop(top)Shape设置元素的垂直位置(以点为单位),当元素未旋转时,该位置从页面的左上角开始测量。
setTransform(transform)Shape使用提供的转换设置页面元素的转换。
setWidth(width)Shape以磅为单位设置元素的宽度,即元素未旋转时,元素边界框的宽度。

详细文档

alignOnPage(alignmentPosition)

将元素与页面上的指定对齐位置对齐。

参数

名称类型说明
alignmentPositionAlignmentPosition相应页面元素在页面上的对齐位置。

返回

Shape - 此页面元素,用于链式调用。


bringForward()

将页面元素在页面上向前移动一个元素。

页面元素不得位于群组中。

返回

Shape - 此页面元素,用于链式调用。

授权

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

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

bringToFront()

将页面元素置于页面最前面。

页面元素不得位于群组中。

返回

Shape - 此页面元素,用于链式调用。

授权

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

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

duplicate()

复制页面元素。

复制的页面元素放置在与原始元素相同的页面和位置。

返回

PageElement -相应页面元素的新副本。

授权

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

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

getAutofit()

返回相应形状内文本的 Autofit。如果形状不允许添加文字,则为 null

返回

Autofit|null - 相应形状内文本的自动调整。

授权

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

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

getBorder()

返回形状的 Border

返回

Border - 相应形状的边框设置。

授权

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

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

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()

返回形状的 Fill

返回

Fill - 相应形状的填充设置。

授权

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

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

getHeight()

获取元素的高度(以磅为单位),即元素未旋转时其边界框的高度。

此方法不适用于所有网页元素。如需了解哪些页面元素与此方法不兼容,请参阅 大小调整和定位限制

返回

Number|null - 页面元素的固有高度(以点为单位),如果页面元素没有高度,则为 null

授权

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

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

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

如果不存在链接,则返回 Linknull

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 - 如果没有链接,则为 Linknull

授权

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

  • 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()

返回相应网页元素所属的组;如果该元素不属于任何组,则返回 null

返回

Group|null - 此网页元素所属的群组,或 null

授权

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

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

getParentPage()

返回相应页面元素所在的页面。

返回

Page - 相应元素所在的网页。

授权

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

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

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

getShapeType()

返回形状的类型。

返回

ShapeType - 此形状的类型。


getText()

返回形状的文本内容。

形状内的文本始终以换行符结尾。

返回

TextRange - 相应形状的文本内容。

授权

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

  • 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()

返回元素的宽度(以磅为单位),即元素未旋转时其边界框的宽度。

此方法不适用于所有网页元素。如需了解哪些页面元素与此方法不兼容,请参阅 大小调整和定位限制

返回

Number|null - 页面元素的固有宽度(以点为单位),如果页面元素没有宽度,则为 null

授权

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

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

preconcatenateTransform(transform)

将提供的转换预串联到网页元素的现有转换。

newTransform = argument * existingTransform;

例如,如需将页面元素向左移动 36 点,请执行以下操作:

const element = SlidesApp.getActivePresentation().getSlides()[0].getPageElements()[0];
element.preconcatenateTransform(
    SlidesApp.newAffineTransformBuilder().setTranslateX(-36.0).build(),
);

您还可以将网页元素的转换替换为 setTransform(transform)

参数

名称类型说明
transformAffineTransform要预先串联到此页面元素的转换的转换。

返回

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

移除 Link

const slides = SlidesApp.getActivePresentation().getSlides();
slides[1].getShapes()[0].removeLink();

replaceWithImage(blobSource)

将此形状替换为 BlobSource 提供的图片。

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

为了保持图片的宽高比,系统会根据现有形状的大小缩放图片并将其居中。

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

参数

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

返回

Image - 替换形状的 Image

授权

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

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

replaceWithImage(blobSource, crop)

将此形状替换为 BlobSource 提供的图片。

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

const shape = SlidesApp.getActivePresentation().getSlides()[0].getShapes()[0];
// Get the Drive image file with the given ID.
const driveImage = DriveApp.getFileById('123abc');
// Replace and crop the replaced image.
shape.replaceWithImage(driveImage, true);

参数

名称类型说明
blobSourceBlobSource图片数据。
cropBoolean如果值为 true,则会裁剪图片以适应现有形状的大小。否则,系统会缩放图片并将其居中。

返回

Image - 替换形状的 Image

授权

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

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

replaceWithImage(imageUrl)

将此形状替换为图片。

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

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

为了保持图片的宽高比,系统会根据现有形状的大小缩放图片并将其居中。

参数

名称类型说明
imageUrlString用于下载图片的图片网址。

返回

Image - 替换形状的 Image

授权

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

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

replaceWithImage(imageUrl, crop)

将此形状替换为图片。

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

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

参数

名称类型说明
imageUrlString用于下载图片的图片网址。
cropBoolean如果值为 true,则会裁剪图片以适应现有形状的大小。否则,系统会缩放图片并将其居中。

返回

Image - 替换形状的 Image

授权

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

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

replaceWithSheetsChart(sourceChart)

将此形状替换为 Google 表格图表。

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

const sheet = SpreadsheetApp.openById('spreadsheetId').getSheets()[0];
const chart = sheet.getCharts()[0];
// Replace the shape with the Sheets chart.
const shape = SlidesApp.getActivePresentation().getSlides()[0].getShapes()[0];
shape.replaceWithSheetsChart(chart);

参数

名称类型说明
sourceChartEmbeddedChart电子表格中用于替换形状的图表。

返回

SheetsChart - 替换形状的图表。

授权

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

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

replaceWithSheetsChartAsImage(sourceChart)

将此形状替换为 Google 表格图表的图片。

为了保持 Google 表格图表的宽高比,系统会根据现有形状的大小缩放图表图片并将其居中放置。

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

const sheet = SpreadsheetApp.openById('spreadsheetId').getSheets()[0];
const chart = sheet.getCharts()[0];
// Replace the shape with the Sheets chart as an image.
const shape = SlidesApp.getActivePresentation().getSlides()[0].getShapes()[0];
shape.replaceWithSheetsChartAsImage(chart);

参数

名称类型说明
sourceChartEmbeddedChart电子表格中用于替换形状的图表。

返回

Image - 取代形状的图表的图片。

授权

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

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

scaleHeight(ratio)

按指定比例缩放元素的高度。当元素未旋转时,元素的高度是其边界框的高度。

此方法不适用于所有网页元素。如需了解哪些页面元素与此方法不兼容,请参阅 大小调整和定位限制

参数

名称类型说明
ratioNumber用于缩放相应网页元素高度的比率。

返回

Shape - 此页面元素,用于链式调用。

授权

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

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

scaleWidth(ratio)

按指定比例缩放元素的宽度。元素的宽度是指元素未旋转时其边界框的宽度。

此方法不适用于所有网页元素。如需了解哪些页面元素与此方法不兼容,请参阅 大小调整和定位限制

参数

名称类型说明
ratioNumber用于缩放相应网页元素宽度的比率。

返回

Shape - 此页面元素,用于链式调用。

授权

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

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

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 参数选择网页元素时,必须满足以下条件:

  1. PageElement 对象的父级 Page 必须是 current page selection
  2. 不应选择多个 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);
}

参数

名称类型说明
replaceBoolean如果值为 true,则所选内容会替换任何先前所选内容;否则,所选内容会添加到任何先前所选内容中。

授权

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

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

sendBackward()

将页面元素在页面上向后移动一个元素。

页面元素不得位于群组中。

返回

Shape - 此页面元素,用于链式调用。

授权

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

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

sendToBack()

将页面元素发送到页面后方。

页面元素不得位于群组中。

返回

Shape - 此页面元素,用于链式调用。

授权

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

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

setContentAlignment(contentAlignment)

设置形状中文字的 ContentAlignment

此方法会自动停用更新后的形状上的文字自动调整属性。

参数

名称类型说明
contentAlignmentContentAlignment要设置的对齐方式。

返回

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".
const pageElement =
    SlidesApp.getActivePresentation().getSlides()[0].getPageElements()[0];
pageElement.setDescription('new alt text description');
Logger.log(pageElement.getDescription());

参数

名称类型说明
descriptionString用于设置替代文本说明的字符串。

返回

Shape - 此页面元素。

授权

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

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

setHeight(height)

以磅为单位设置元素的高度,即元素在未旋转时其边界框的高度。

此方法不适用于所有网页元素。如需了解哪些页面元素与此方法不兼容,请参阅 大小调整和定位限制

参数

名称类型说明
heightNumber要设置的相应页面元素的新高度(以点为单位)。

返回

Shape - 此页面元素,用于链式调用。

授权

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

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

setLeft(left)

设置元素在页面中的水平位置(以点为单位),该位置从元素的左上角开始测量(当元素未旋转时)。

参数

名称类型说明
leftNumber要设置的新水平位置(以点为单位)。

返回

Shape - 此页面元素,用于链式调用。

授权

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

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

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);

参数

名称类型说明
slideIndexInteger幻灯片的索引(从零开始)。

返回

Link - 已设置的 Link

授权

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

  • 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]);

参数

名称类型说明
slideSlide要关联的 Slide

返回

Link - 已设置的 Link

授权

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

  • 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);

参数

名称类型说明
slidePositionSlidePosition相对 SlidePosition

返回

Link - 已设置的 Link

授权

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

  • 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');

参数

名称类型说明
urlString网址字符串。

返回

Link - 已设置的 Link

授权

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

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

setRotation(angle)

设置元素围绕其中心顺时针旋转的角度(以度为单位)。

此方法不适用于所有网页元素。如需了解哪些页面元素与此方法不兼容,请参阅 大小调整和定位限制

参数

名称类型说明
angleNumber要设置的新顺时针旋转角度(以度为单位)。

返回

Shape - 此页面元素,用于链式调用。

授权

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

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

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());

参数

名称类型说明
titleString要将替代文本标题设置为的字符串。

返回

Shape - 此页面元素。

授权

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

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

setTop(top)

设置元素的垂直位置(以点为单位),当元素未旋转时,该位置从页面的左上角开始测量。

参数

名称类型说明
topNumber要设置的新垂直位置(以点为单位)。

返回

Shape - 此页面元素,用于链式调用。

授权

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

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

setTransform(transform)

使用提供的转换设置页面元素的转换。

更新组的转换会更改该组中页面元素的绝对转换,从而改变其视觉外观。

更新组中某个页面元素的转换只会更改该页面元素的转换,而不会影响组或组中其他页面元素的转换。

如需详细了解转换如何影响网页元素的视觉外观,请参阅 getTransform()

参数

名称类型说明
transformAffineTransform为相应网页元素设置的转换。

返回

Shape - 此元素,用于链式调用。

授权

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

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

setWidth(width)

以磅为单位设置元素的宽度,即元素在未旋转时其边界框的宽度。

此方法不适用于所有网页元素。如需了解哪些页面元素与此方法不兼容,请参阅 大小调整和定位限制

参数

名称类型说明
widthNumber要设置的相应页面元素的新宽度(以磅为单位)。

返回

Shape - 此页面元素,用于链式调用。

授权

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

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