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 之間 (含 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 擷取圖片,並儲存副本以在簡報中顯示。圖片大小不得超過 50 MB,像素不得超過 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 擷取圖片一次,並儲存副本,以便在簡報中顯示。圖片大小不得超過 50 MB,像素不得超過 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)

使用圖片取代這個圖案。

插入圖片時,系統會從網址擷取圖片一次,並儲存副本,以便在簡報中顯示。圖片大小不得超過 50 MB,像素不得超過 2500 萬,且格式必須為 PNG、JPEG 或 GIF。

提供的網址必須可供所有人存取,且大小不得超過 2 KB。網址本身會與圖片一併儲存,並透過 Image.getSourceUrl() 公開。

為維持圖片的顯示比例,系統會根據現有圖案的大小縮放圖片並置中。

參數

名稱類型說明
imageUrlString可從中下載圖片的圖片網址。

回攻員

Image:取代圖形的 Image

授權

使用這個方法的指令碼需要一或多個下列範圍的授權:

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

replaceWithImage(imageUrl, crop)

使用圖片取代這個圖案。

插入圖片時,系統會從網址擷取圖片一次,並儲存副本,以便在簡報中顯示。圖片大小不得超過 50 MB,像素不得超過 2500 萬,且格式必須為 PNG、JPEG 或 GIF。

提供的網址不得超過 2 KB。網址本身會與圖片一併儲存,並透過 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)

將指定 SlideLink 設為指定投影片 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