PageElement
代表沒有更具體分類的一般形狀。包括文字方塊、矩形和其他預先定義的形狀。
方法
內容詳盡的說明文件
alignOnPage(alignmentPosition)
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
中擷取圖片一次,並儲存副本,以便在簡報中顯示。圖片檔案大小不得超過 50 MB,不得超過 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
擷取圖片一次,並儲存副本,以便在簡報中顯示。圖片必須小於 50 MB、不得超過 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)
將此形狀換成圖片。
插入圖片後,系統會從網址擷取圖片一次,並儲存副本,以供在簡報中顯示。圖片必須小於 50 MB、不得超過 2500 萬像素,且格式須為 PNG、JPEG 或 GIF。
提供的網址必須可公開存取,且大小不得超過 2 KB。網址本身會與圖片一併儲存,並透過 Image.getSourceUrl()
公開。
為了維持圖片的長寬比,系統會根據現有形狀的大小,縮放圖片並將其置中。
參數
名稱 | 類型 | 說明 |
---|---|---|
imageUrl | String | 圖片下載來源的圖片網址。 |
回攻員
授權
使用這個方法的指令碼需要下列一或多個範圍的授權:
-
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()
公開。
參數
名稱 | 類型 | 說明 |
---|---|---|
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