Class Slide

滑動

簡報中的投影片。

這些網頁包含您向觀眾呈現的內容。大多數投影片都是以母片和版面配置為基礎。建立投影片時,您可以指定每張投影片要使用的版面配置。

方法

方法傳回類型簡短說明
duplicate()Slide複製投影片。
getBackground()PageBackground取得頁面的背景。
getColorScheme()ColorScheme取得與網頁相關聯的 ColorScheme
getGroups()Group[]傳回頁面上的 Group 物件清單。
getImages()Image[]傳回頁面上的 Image 物件清單。
getLayout()Layout|null取得投影片所依據的版面配置,或投影片並非依據版面配置時的 null
getLines()Line[]傳回頁面上的 Line 物件清單。
getNotesPage()NotesPage傳回與投影片相關聯的附註頁面。
getObjectId()String取得網頁的專屬 ID。
getPageElementById(id)PageElement|null傳回具有指定 ID 的頁面上的 PageElement,如果沒有則傳回 null
getPageElements()PageElement[]傳回頁面上顯示的 PageElement 物件清單。
getPageType()PageType取得網頁類型。
getPlaceholder(placeholderType)PageElement|null傳回指定 PlaceholderType 的預留位置 PageElement 物件,或如果沒有相符的預留位置,則傳回 null
getPlaceholder(placeholderType, placeholderIndex)PageElement|null傳回指定 PlaceholderType 和預留位置索引的預留位置 PageElement 物件,如果沒有預留位置,則傳回 null
getPlaceholders()PageElement[]傳回頁面中的預留位置 PageElement 物件清單。
getShapes()Shape[]傳回頁面上的 Shape 物件清單。
getSheetsCharts()SheetsChart[]傳回頁面上的 SheetsChart 物件清單。
getSlideLinkingMode()SlideLinkingMode傳回 SlideLinkingMode,指出投影片是否連結至其他投影片。
getSourcePresentationId()String如果投影片未連結,則傳回來源 Presentation ID 或 null
getSourceSlideObjectId()String傳回來源投影片 ID,如果投影片未連結,則傳回 null
getTables()Table[]傳回頁面上的 Table 物件清單。
getVideos()Video[]傳回頁面上的 Video 物件清單。
getWordArts()WordArt[]傳回頁面上的 WordArt 物件清單。
group(pageElements)Group將所有指定的頁面元素分組。
insertGroup(group)Group在頁面上插入所提供 Group 的副本。
insertImage(blobSource)Image在頁面左上角插入圖片,圖片大小預設為指定圖片 Blob 的大小。
insertImage(blobSource, left, top, width, height)Image在頁面上插入圖片,圖片位置和大小取自指定的圖片 Blob。
insertImage(image)Image在頁面上插入所提供 Image 的副本。
insertImage(imageUrl)Image從提供的網址插入圖片,並將圖片放在頁面左上角,大小則採用預設值。
insertImage(imageUrl, left, top, width, height)Image從提供的網址插入圖片,並在頁面上指定圖片位置和大小。
insertLine(line)Line在頁面上插入所提供 Line 的副本。
insertLine(lineCategory, startConnectionSite, endConnectionSite)Line在頁面上插入連結兩個 connection sites 的線條。
insertLine(lineCategory, startLeft, startTop, endLeft, endTop)Line在頁面中插入一行。
insertPageElement(pageElement)PageElement在頁面上插入所提供 PageElement 的副本。
insertShape(shape)Shape在頁面上插入所提供 Shape 的副本。
insertShape(shapeType)Shape在頁面上插入圖案。
insertShape(shapeType, left, top, width, height)Shape在頁面上插入圖案。
insertSheetsChart(sourceChart)SheetsChart在網頁上插入 Google 試算表圖表。
insertSheetsChart(sourceChart, left, top, width, height)SheetsChart在頁面上插入 Google 試算表圖表,並指定位置和大小。
insertSheetsChart(sheetsChart)SheetsChart在頁面上插入所提供 SheetsChart 的副本。
insertSheetsChartAsImage(sourceChart)Image在頁面上插入 Google 試算表圖表,顯示為 Image
insertSheetsChartAsImage(sourceChart, left, top, width, height)Image在網頁中插入 Google 試算表圖表,並提供位置和大小。Image
insertTable(numRows, numColumns)Table在頁面上插入表格。
insertTable(numRows, numColumns, left, top, width, height)Table在頁面上插入表格,並指定位置和大小。
insertTable(table)Table在頁面上插入所提供 Table 的副本。
insertTextBox(text)Shape在網頁上插入包含所提供字串的文字方塊 Shape
insertTextBox(text, left, top, width, height)Shape在網頁上插入包含所提供字串的文字方塊 Shape
insertVideo(videoUrl)Video在頁面左上角插入預設大小的影片。
insertVideo(videoUrl, left, top, width, height)Video在網頁上插入影片,並指定位置和大小。
insertVideo(video)Video在頁面上插入所提供 Video 的副本。
insertWordArt(wordArt)WordArt在頁面上插入所提供 WordArt 的副本。
isSkipped()Boolean傳回投影片是否在簡報模式中略過。
move(index)void將投影片移至指定索引。
refreshSlide()void重新整理投影片,反映連結來源投影片的任何變更。
remove()void移除頁面。
replaceAllText(findText, replaceText)Integer將所有符合「尋找文字」的文字例項替換為「取代文字」。
replaceAllText(findText, replaceText, matchCase)Integer將所有符合「尋找文字」的文字例項替換為「取代文字」。
selectAsCurrentPage()void選取目前簡報中的 Page 做為 current page selection,並移除先前的選取項目。
setSkipped(isSkipped)void設定是否要在簡報模式中略過投影片。
unlink()void取消連結目前的 Slide 與來源投影片。

內容詳盡的說明文件

duplicate()

複製投影片。

系統會立即在原始投影片後方建立副本。

回攻員

Slide:複製的投影片。

授權

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

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

getBackground()

取得頁面的背景。

回攻員

PageBackground:頁面背景。

授權

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

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

getColorScheme()

取得與網頁相關聯的 ColorScheme

回攻員

ColorScheme:網頁的色彩配置。

授權

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

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

getGroups()

傳回頁面上的 Group 物件清單。

回攻員

Group[]

授權

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

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

getImages()

傳回頁面上的 Image 物件清單。

回攻員

Image[]

授權

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

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

getLayout()

取得投影片所依據的版面配置,或投影片並非依據版面配置時的 null

回攻員

Layout|null

授權

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

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

getLines()

傳回頁面上的 Line 物件清單。

回攻員

Line[]

授權

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

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

getNotesPage()

傳回與投影片相關聯的附註頁面。

回攻員

NotesPage

授權

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

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

getObjectId()

取得網頁的專屬 ID。網頁和網頁元素使用的物件 ID 共用相同的命名空間。

回攻員

String

授權

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

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

getPageElementById(id)

傳回具有指定 ID 的頁面上的 PageElement,如果沒有則傳回 null

參數

名稱類型說明
idString要擷取的網頁元素 ID。

回攻員

PageElement|null:具有指定 ID 的頁面元素。

授權

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

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

getPageElements()

傳回頁面上顯示的 PageElement 物件清單。

回攻員

PageElement[]

授權

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

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

getPageType()

取得網頁類型。

回攻員

PageType:網頁類型。

授權

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

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

getPlaceholder(placeholderType)

傳回指定 PlaceholderType 的預留位置 PageElement 物件,或如果沒有相符的預留位置,則傳回 null

如果有多個相同類型的預留位置,系統會傳回預留位置索引最小的預留位置。如果有多個相符的預留位置具有相同索引,系統會從網頁的網頁元素集合傳回第一個預留位置。

const slide = SlidesApp.getActivePresentation().getSlides()[0];
const placeholder = slide.getPlaceholder(
    SlidesApp.PlaceholderType.CENTERED_TITLE,
);

參數

名稱類型說明
placeholderTypePlaceholderType

回攻員

PageElement|null

授權

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

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

getPlaceholder(placeholderType, placeholderIndex)

傳回指定 PlaceholderType 和預留位置索引的預留位置 PageElement 物件,如果沒有預留位置,則傳回 null

如果有多個相同類型和索引的預留位置,系統會從網頁的網頁元素集合傳回第一個預留位置。

const slide = SlidesApp.getActivePresentation().getSlides()[0];
const placeholder = slide.getPlaceholder(
    SlidesApp.PlaceholderType.CENTERED_TITLE,
    0,
);

參數

名稱類型說明
placeholderTypePlaceholderType
placeholderIndexInteger

回攻員

PageElement|null

授權

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

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

getPlaceholders()

傳回頁面中的預留位置 PageElement 物件清單。

const master = SlidesApp.getActivePresentation().getMasters()[0];
Logger.log(
    `Number of placeholders in the master: ${master.getPlaceholders().length}`,
);

回攻員

PageElement[]

授權

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

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

getShapes()

傳回頁面上的 Shape 物件清單。

回攻員

Shape[]

授權

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

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

getSheetsCharts()

傳回頁面上的 SheetsChart 物件清單。

回攻員

SheetsChart[]

授權

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

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

getSlideLinkingMode()

傳回 SlideLinkingMode,指出投影片是否連結至其他投影片。

回攻員

SlideLinkingMode:投影片連結模式。

授權

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

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

getSourcePresentationId()

如果投影片未連結,則傳回來源 Presentation ID 或 null

只有連結至其他簡報中的投影片時,投影片才會有來源 Presentation ID。

回攻員

String:來源簡報 ID 或 null

授權

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

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

getSourceSlideObjectId()

傳回來源投影片 ID,如果投影片未連結,則傳回 null

只有在投影片連結至其他簡報中的投影片時,投影片才會有來源投影片 ID。

回攻員

String:來源投影片 ID 或 null

授權

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

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

getTables()

傳回頁面上的 Table 物件清單。

回攻員

Table[]

授權

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

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

getVideos()

傳回頁面上的 Video 物件清單。

回攻員

Video[]

授權

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

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

getWordArts()

傳回頁面上的 WordArt 物件清單。

回攻員

WordArt[]

授權

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

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

group(pageElements)

將所有指定的頁面元素分組。

同一頁面上至少要有兩個尚未加入其他群組的頁面元素。部分網頁元素 (例如 VideosTablesplaceholder Shapes) 無法加入群組。

參數

名稱類型說明
pageElementsPageElement[]要分組的元素。

回攻員

Group:新群組。

授權

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

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

insertGroup(group)

在頁面上插入所提供 Group 的副本。

插入元素在這個頁面上的位置,取決於來源元素在各自頁面上的位置。

如果提供的元素是從目前簡報複製的預留位置,則從母版或版面配置頁面繼承的屬性也會繼承至插入的元素。

如果提供的元素是從其他簡報複製的預留位置,系統會將從來源簡報繼承自母片或版面配置頁面的屬性複製到該元素。

// Copy a group between presentations.
const otherPresentationSlide =
    SlidesApp.openById('presentationId').getSlides()[0];
const currentPresentationSlide =
    SlidesApp.getActivePresentation().getSlides()[0];
const group = otherPresentationSlide.getGroups()[0];
currentPresentationSlide.insertGroup(
    group);  // Also available for Layout, Master, and Page.

參數

名稱類型說明
groupGroup要複製及插入的群組。

回攻員

Group:插入的群組。

授權

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

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

insertImage(blobSource)

在頁面左上角插入圖片,並根據指定的圖片 Blob 設定預設大小。

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

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

參數

名稱類型說明
blobSourceBlobSource圖片資料。

回攻員

Image:插入的圖片。

授權

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

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

insertImage(blobSource, left, top, width, height)

在頁面上插入圖片,圖片位置和大小取自指定的圖片 Blob。

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

為維持圖片的顯示比例,系統會根據提供的尺寸縮放圖片並置中。

const slide = SlidesApp.getActivePresentation().getSlides()[0];
// Get the Drive image file with the given ID.
const image = DriveApp.getFileById('123abc');
const position = {
  left: 0,
  top: 0
};
const size = {
  width: 300,
  height: 100
};
slide.insertImage(image, position.left, position.top, size.width, size.height);

參數

名稱類型說明
blobSourceBlobSource圖片資料。
leftNumber圖片的水平位置 (以點為單位),從頁面左上角開始測量。
topNumber圖片的垂直位置 (以點為單位),從頁面左上角開始計算。
widthNumber圖片寬度 (以點為單位)。
heightNumber圖片的高度 (以點為單位)。

回攻員

Image:插入的圖片。

授權

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

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

insertImage(image)

在頁面上插入所提供 Image 的副本。

插入圖片在這個頁面上的位置,取決於來源圖片在各自頁面上的位置。

如果提供的圖片是從目前簡報內複製的預留位置,從母片或版面配置頁面繼承的屬性也會繼承到插入的圖片上。

如果提供的圖片是從其他簡報複製的預留位置,系統會將從來源簡報繼承的屬性複製到圖片上。如果複製的預留位置圖片為空白,系統不會在目標簡報中插入任何內容。

// Copy an image between presentations.
const otherPresentationSlide =
    SlidesApp.openById('presentationId').getSlides()[0];
const currentPresentationSlide =
    SlidesApp.getActivePresentation().getSlides()[0];
const image = otherPresentationSlide.getImages[0];
currentPresentationSlide.insertImage(image);

參數

名稱類型說明
imageImage要複製及插入的圖片。

回攻員

Image:插入的圖片。

授權

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

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

insertImage(imageUrl)

從提供的網址插入圖片,並將圖片放在頁面左上角,大小則採用預設值。

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

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

參數

名稱類型說明
imageUrlString圖片網址。

回攻員

Image:插入的圖片。

授權

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

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

insertImage(imageUrl, left, top, width, height)

從提供的網址插入圖片,並在頁面上指定位置和大小。

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

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

為維持圖片的顯示比例,系統會根據提供的尺寸縮放圖片並置中。

參數

名稱類型說明
imageUrlString圖片網址。
leftNumber圖片的水平位置 (以點為單位),從頁面左上角開始測量。
topNumber圖片的垂直位置 (以點為單位),從頁面左上角開始計算。
widthNumber圖片寬度 (以點為單位)。
heightNumber圖片的高度 (以點為單位)。

回攻員

Image:插入的圖片。

授權

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

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

insertLine(line)

在頁面上插入所提供 Line 的副本。

插入元素在這個頁面上的位置,取決於來源元素在各自頁面上的位置。

如果提供的元素是從目前簡報複製的預留位置,則從母版或版面配置頁面繼承的屬性也會繼承至插入的元素。

如果提供的元素是從其他簡報複製的預留位置,系統會將從來源簡報繼承自母片或版面配置頁面的屬性複製到該元素。

// Copy a line between presentations.
const otherPresentationSlide =
    SlidesApp.openById('presentationId').getSlides()[0];
const currentPresentationSlide =
    SlidesApp.getActivePresentation().getSlides()[0];
const line = otherPresentationSlide.getLines[0];
currentPresentationSlide.insertLine(line);

參數

名稱類型說明
lineLine要複製及插入的行。

回攻員

Line:插入的行。

授權

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

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

insertLine(lineCategory, startConnectionSite, endConnectionSite)

在頁面上插入連結兩個 connection sites 的線條。這個頁面必須顯示兩個連線網站。

// Insert a line in the first slide of the presentation connecting two shapes.
const slide = SlidesApp.getActivePresentation().getSlides()[0];
const shape1 = slide.insertShape(SlidesApp.ShapeType.RECTANGLE);
const shape2 = slide.insertShape(SlidesApp.ShapeType.CLOUD);
slide.insertLine(
    SlidesApp.LineCategory.BENT,
    shape1.getConnectionSites()[0],
    shape2.getConnectionSites()[1],
);

參數

名稱類型說明
lineCategoryLineCategory要插入的線條類別。
startConnectionSiteConnectionSite要連接線條起點的連接點。
endConnectionSiteConnectionSite線條末端要連接的連接點。

回攻員

Line:插入的行。

授權

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

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

insertLine(lineCategory, startLeft, startTop, endLeft, endTop)

在頁面中插入一行。

// Insert a line in the first slide of the presentation.
const slide = SlidesApp.getActivePresentation().getSlides()[0];
const startPoint = {
  left: 10,
  top: 10
};
const endPoint = {
  left: 40,
  top: 40
};
slide.insertLine(
    SlidesApp.LineCategory.STRAIGHT,
    startPoint.left,
    startPoint.top,
    endPoint.left,
    endPoint.top,
);

參數

名稱類型說明
lineCategoryLineCategory要插入的線條類別。
startLeftNumber線條起點的水平位置,以點為單位,從頁面左上角開始測量。
startTopNumber線條起點的垂直位置,以頁面左上角為準,單位為點。
endLeftNumber線條終點的水平位置,以點為單位,從頁面左上角開始測量。
endTopNumber線條終點的垂直位置,以點為單位,從頁面左上角算起。

回攻員

Line:插入的行。

授權

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

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

insertPageElement(pageElement)

在頁面上插入所提供 PageElement 的副本。

插入元素在這個頁面上的位置,取決於來源元素在各自頁面上的位置。

如果提供的元素是從目前簡報複製的預留位置,則從母版或版面配置頁面繼承的屬性也會繼承至插入的元素。

如果提供的元素是從其他簡報複製的預留位置,系統會將從來源簡報繼承自母片或版面配置頁面的屬性複製到該元素。

// Copy a page element between presentations.
const otherPresentationSlide =
    SlidesApp.openById('presentationId').getSlides()[0];
const currentPresentationSlide =
    SlidesApp.getActivePresentation().getSlides()[0];
const pageElement = otherPresentationSlide.getPageElements()[0];

// Also available for Layout, Master, and Page.
currentPresentationSlide.insertPageElement(pageElement);

參數

名稱類型說明
pageElementPageElement要複製及插入的頁面元素。

回攻員

PageElement:插入的網頁元素。

授權

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

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

insertShape(shape)

在頁面上插入所提供 Shape 的副本。

插入元素在這個頁面上的位置,取決於來源元素在各自頁面上的位置。

如果提供的元素是從目前簡報複製的預留位置,則從母版或版面配置頁面繼承的屬性也會繼承至插入的元素。

如果提供的元素是從其他簡報複製的預留位置,系統會將從來源簡報繼承自母片或版面配置頁面的屬性複製到該元素。

// Copy a shape between presentations.
const otherPresentationSlide =
    SlidesApp.openById('presentationId').getSlides()[0];
const currentPresentationSlide =
    SlidesApp.getActivePresentation().getSlides()[0];
const shape = otherPresentationSlide.getShapes[0];
currentPresentationSlide.insertShape(
    shape);  // Also available for Layout, Master, and Page.

參數

名稱類型說明
shapeShape要複製及插入的形狀。

回攻員

Shape:插入的形狀。

授權

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

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

insertShape(shapeType)

在頁面上插入圖案。

形狀會以預設大小插入頁面左上角。

// Insert a shape in the first slide of the presentation.
const slide = SlidesApp.getActivePresentation().getSlides()[0];

// Also available for Layout, Master, and Page.
slide.insertShape(SlidesApp.ShapeType.RECTANGLE);

參數

名稱類型說明
shapeTypeShapeType要插入的圖案類型。

回攻員

Shape:插入的形狀。

授權

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

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

insertShape(shapeType, left, top, width, height)

在頁面上插入圖案。

參數

名稱類型說明
shapeTypeShapeType要插入的圖案類型。
leftNumber形狀的水平位置,從頁面左上角算起。
topNumber形狀的垂直位置,從頁面左上角開始測量。
widthNumber形狀的寬度。
heightNumber形狀的高度。

回攻員

Shape:插入的形狀。

授權

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

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

insertSheetsChart(sourceChart)

在網頁上插入 Google 試算表圖表。

圖表會以預設大小插入頁面左上角。

插入的圖表會連結至來源 Google 試算表圖表,因此可以更新。其他協作者可以查看來源試算表的連結。

const sheet = SpreadsheetApp.openById('spreadsheetId').getSheets()[0];
const chart = sheet.getCharts()[0];
// Insert the spreadsheet chart in the first slide.
const slide = SlidesApp.getActivePresentation().getSlides()[0];
slide.insertSheetsChart(chart);

參數

名稱類型說明
sourceChartEmbeddedChart要插入頁面的試算表圖表。

回攻員

SheetsChart:插入頁面的圖表。

授權

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

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

insertSheetsChart(sourceChart, left, top, width, height)

在頁面上插入 Google 試算表圖表,並指定位置和大小。

為維持圖表的顯示比例,系統會根據提供的尺寸縮放圖表,並將其置中。

插入的圖表會連結至來源 Google 試算表圖表,因此可以更新。其他協作者可以查看來源試算表的連結。

const sheet = SpreadsheetApp.openById('spreadsheetId').getSheets()[0];
const chart = sheet.getCharts()[0];
// Insert the spreadsheet chart in the first slide.
const slide = SlidesApp.getActivePresentation().getSlides()[0];
const position = {
  left: 0,
  top: 0
};
const size = {
  width: 200,
  height: 200
};

// Also available for Layout, Master, and Page.
slide.insertSheetsChart(
    chart,
    position.left,
    position.top,
    size.width,
    size.height,
);

參數

名稱類型說明
sourceChartEmbeddedChart要插入頁面的試算表圖表。
leftNumber圖表在頁面中的水平位置 (以點為單位),從頁面左上角開始計算。
topNumber圖表的垂直位置 (以點為單位),從頁面左上角開始測量。
widthNumber圖表的寬度 (以點為單位)。
heightNumber圖表的高度 (以點為單位)。

回攻員

SheetsChart:插入頁面的圖表。

授權

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

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

insertSheetsChart(sheetsChart)

在頁面上插入所提供 SheetsChart 的副本。

插入元素在這個頁面上的位置,取決於來源元素在各自頁面上的位置。

如果提供的元素是從目前簡報複製的預留位置,則從母版或版面配置頁面繼承的屬性也會繼承至插入的元素。

如果提供的元素是從其他簡報複製的預留位置,系統會將從來源簡報繼承自母片或版面配置頁面的屬性複製到該元素。

// Copy a sheets chart between presentations.
const otherPresentationSlide =
    SlidesApp.openById('presentationId').getSlides()[0];
const currentPresentationSlide =
    SlidesApp.getActivePresentation().getSlides()[0];
const sheetsChart = otherPresentationSlide.getSheetsCharts[0];

// Also available for Layout, Master, and Page.
currentPresentationSlide.insertSheetsChart(sheetsChart);

參數

名稱類型說明
sheetsChartSheetsChart要複製及插入的試算表圖表。

回攻員

SheetsChart - 插入的試算表圖表。

授權

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

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

insertSheetsChartAsImage(sourceChart)

在頁面上插入 Google 試算表圖表,顯示為 Image

圖表圖片會以預設大小插入頁面左上角。

插入的圖表圖片未連結至來源 Google 試算表圖表。

const sheet = SpreadsheetApp.openById('spreadsheetId').getSheets()[0];
const chart = sheet.getCharts()[0];
// Insert the spreadsheet chart in the first slide.
const slide = SlidesApp.getActivePresentation().getSlides()[0];
slide.insertSheetsChartAsImage(
    chart);  // Also available for Layout, Master, and Page.

參數

名稱類型說明
sourceChartEmbeddedChart要插入頁面的試算表圖表。

回攻員

Image:插入頁面的圖表圖片。

授權

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

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

insertSheetsChartAsImage(sourceChart, left, top, width, height)

在網頁中插入 Google 試算表圖表,並提供位置和大小。Image

為維持圖表圖片的顯示比例,系統會根據提供的尺寸縮放圖片並置中。

插入的圖表圖片不會連結至來源 Google 試算表圖表。

const sheet = SpreadsheetApp.openById('spreadsheetId').getSheets()[0];
const chart = sheet.getCharts()[0];
// Insert the spreadsheet chart in the first slide.
const slide = SlidesApp.getActivePresentation().getSlides()[0];
const position = {
  left: 0,
  top: 0
};
const size = {
  width: 200,
  height: 200
};

// Also available for Layout, Master, and Page.
slide.insertSheetsChartAsImage(
    chart,
    position.left,
    position.right,
    size.width,
    size.height,
);

參數

名稱類型說明
sourceChartEmbeddedChart要插入頁面的試算表圖表。
leftNumber圖表在頁面中的水平位置 (以點為單位),從頁面左上角開始計算。
topNumber圖表的垂直位置 (以點為單位),從頁面左上角開始測量。
widthNumber圖表的寬度 (以點為單位)。
heightNumber圖表的高度 (以點為單位)。

回攻員

Image:插入頁面的圖表圖片。

授權

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

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

insertTable(numRows, numColumns)

在頁面上插入表格。

表格會以預設大小置中顯示在頁面上,且資料列和資料欄會平均分配。

參數

名稱類型說明
numRowsInteger資料表中的資料列數。
numColumnsInteger資料表中的欄數。

回攻員

Table:插入的表格。

授權

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

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

insertTable(numRows, numColumns, left, top, width, height)

在頁面上插入指定位置和大小的表格。

系統會平均分配所建立表格的列高和欄寬。

參數

名稱類型說明
numRowsInteger資料表中的資料列數。
numColumnsInteger資料表中的欄數。
leftNumber表格的水平位置,從頁面左上角開始測量。
topNumber表格的垂直位置,從頁面左上角算起。
widthNumber資料表的寬度。
heightNumber表格的最小高度。實際高度取決於文字字型大小等因素。

回攻員

Table:插入的表格。

授權

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

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

insertTable(table)

在頁面上插入所提供 Table 的副本。

插入元素在這個頁面上的位置,取決於來源元素在各自頁面上的位置。

如果提供的元素是從目前簡報複製的預留位置,則從母版或版面配置頁面繼承的屬性也會繼承至插入的元素。

如果提供的元素是從其他簡報複製的預留位置,系統會將從來源簡報繼承自母片或版面配置頁面的屬性複製到該元素。

// Copy a table between presentations.
const otherPresentationSlide =
    SlidesApp.openById('presentationId').getSlides()[0];
const currentPresentationSlide =
    SlidesApp.getActivePresentation().getSlides()[0];
const table = otherPresentationSlide.getTables[0];
currentPresentationSlide.insertTable(
    table);  // Also available for Layout, Master, and Page.

參數

名稱類型說明
tableTable要複製及插入的表格。

回攻員

Table:插入的表格。

授權

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

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

insertTextBox(text)

在網頁上插入包含所提供字串的文字方塊 Shape

文字方塊形狀會以預設大小插入頁面左上角。

// Insert text box with "Hello" on the first slide of presentation.
const slide = SlidesApp.getActivePresentation().getSlides()[0];
slide.insertTextBox('Hello');  // Also available for Layout, Master, and Page.

參數

名稱類型說明
textString文字方塊圖案應包含的字串。

回攻員

Shape - 插入的文字方塊圖案。

授權

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

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

insertTextBox(text, left, top, width, height)

在網頁上插入包含所提供字串的文字方塊 Shape

// Insert text box with "Hello" on the first slide of presentation. This text
// box is a square with a length of 10 points on each side.
const slide = SlidesApp.getActivePresentation().getSlides()[0];
slide.insertTextBox(
    'Hello', 0, 0, 10, 10);  // Also available for Layout, Master, and Page.

參數

名稱類型說明
textString文字方塊圖案應包含的字串。
leftNumber文字方塊形狀的水平位置,從頁面左上角開始測量。
topNumber文字方塊形狀的垂直位置,從頁面左上角算起。
widthNumber文字方塊形狀的寬度。
heightNumber文字方塊形狀的高度。

回攻員

Shape - 插入的文字方塊圖案。

授權

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

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

insertVideo(videoUrl)

在頁面左上角插入預設大小的影片。

目前僅支援 YouTube 影片。

參數

名稱類型說明
videoUrlString要插入的影片網址。

回攻員

Video:插入的影片。

授權

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

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

insertVideo(videoUrl, left, top, width, height)

在網頁上插入影片,並指定位置和大小。

目前僅支援 YouTube 影片。

參數

名稱類型說明
videoUrlString要插入的影片網址。
leftNumber影片的水平位置 (以點為單位),從頁面左上角開始計算。
topNumber影片的垂直位置 (以點為單位),從頁面左上角開始計算。
widthNumber影片寬度 (以點為單位)。
heightNumber影片高度 (以點為單位)。

回攻員

Video:插入的影片。

授權

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

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

insertVideo(video)

在頁面上插入所提供 Video 的副本。

插入元素在這個頁面上的位置,取決於來源元素在各自頁面上的位置。

如果提供的元素是從目前簡報複製的預留位置,則從母版或版面配置頁面繼承的屬性也會繼承至插入的元素。

如果提供的元素是從其他簡報複製的預留位置,系統會將從來源簡報繼承自母片或版面配置頁面的屬性複製到該元素。

// Copy a video between presentations.
const otherPresentationSlide =
    SlidesApp.openById('presentationId').getSlides()[0];
const currentPresentationSlide =
    SlidesApp.getActivePresentation().getSlides()[0];
const video = otherPresentationSlide.getVideos[0];
currentPresentationSlide.insertVideo(
    video);  // Also available for Layout, Master, and Page.

參數

名稱類型說明
videoVideo要複製及插入的影片。

回攻員

Video:插入的影片。

授權

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

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

insertWordArt(wordArt)

在頁面上插入所提供 WordArt 的副本。

插入元素在這個頁面上的位置,取決於來源元素在各自頁面上的位置。

如果提供的元素是從目前簡報複製的預留位置,則從母版或版面配置頁面繼承的屬性也會繼承至插入的元素。

如果提供的元素是從其他簡報複製的預留位置,系統會將從來源簡報繼承自母片或版面配置頁面的屬性複製到該元素。

// Copy a word art between presentations.
const otherPresentationSlide =
    SlidesApp.openById('presentationId').getSlides()[0];
const currentPresentationSlide =
    SlidesApp.getActivePresentation().getSlides()[0];
const wordArt = otherPresentationSlide.getWordArts[0];

// Also available for Layout, Master, and Page.
currentPresentationSlide.insertWordArt(wordArt);

參數

名稱類型說明
wordArtWordArt要複製及插入的群組。

回攻員

WordArt:插入的文字藝術。

授權

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

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

isSkipped()

傳回投影片是否在簡報模式中略過。

回攻員

Boolean - True 如果系統在簡報模式中略過投影片。

授權

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

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

move(index)

將投影片移至指定索引。

參數

名稱類型說明
indexInteger投影片應移至的索引,以移動前的投影片排列方式為準。索引應介於零和簡報中的投影片數量之間 (含首尾)。

授權

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

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

refreshSlide()

重新整理投影片,反映連結來源投影片的任何變更。如果這個投影片未連結,則會傳回而不進行任何變更。

如果連結來源投影片的對應母片和版面配置頁面不存在,refreshSlide 方法會將這些頁面複製到投影片的簡報中。如果這些項目已存在,系統也會更新這些項目,反映來源所做的任何變更。

const currentPresentation = SlidesApp.getActivePresentation();
const sourcePresentation = SlidesApp.openById('sourcePresentationId');
const sourceSlide = sourcePresentation.getSlides()[0];
const linkedSlide = currentPresentation.append(
    sourceSlide,
    SlidesApp.SlideLinkingMode.LINKED,
);

sourceSlide.insertText(
    'hello world');  // Only the source slide has the text box.

linkedSlide.refreshSlide();  // The linked slide now has the text box.

擲回

Error - 如果無法再讀取來源簡報。

授權

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

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

remove()

移除頁面。

授權

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

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

replaceAllText(findText, replaceText)

將所有符合「尋找文字」的文字例項替換為「取代文字」。搜尋時不區分大小寫。

參數

名稱類型說明
findTextString要尋找的文字。
replaceTextString要用來取代相符文字的文字。

回攻員

Integer - 發生次數已變更

授權

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

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

replaceAllText(findText, replaceText, matchCase)

將所有符合「尋找文字」的文字例項替換為「取代文字」。

參數

名稱類型說明
findTextString要尋找的文字。
replaceTextString要用來取代相符文字的文字。
matchCaseBoolean如果顯示 true,搜尋時會區分大小寫;如果顯示 false,搜尋時不會區分大小寫。

回攻員

Integer - 發生次數已變更

授權

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

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

selectAsCurrentPage()

選取目前簡報中的 Page,做為 current page selection,並移除先前選取的項目。

指令碼只能存取執行指令碼的使用者選取的內容,且指令碼必須繫結至簡報。

// Select the first slide as the current page selection and replace any previous
// selection.
const slide = SlidesApp.getActivePresentation().getSlides()[0];
slide.selectAsCurrentPage();  // Also available for Layout, Master, and Page.

授權

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

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

setSkipped(isSkipped)

設定是否要在簡報模式中略過投影片。

參數

名稱類型說明
isSkippedBooleanTrue 即可在簡報模式中略過投影片。

授權

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

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

取消連結目前的 Slide 與來源投影片。如果這個投影片未連結,則會傳回而不進行任何變更。

const currentPresentation = SlidesApp.getActivePresentation();
const sourcePresentation = SlidesApp.openById('sourcePresentationId');
const sourceSlide = sourcePresentation.getSlides()[0];
const linkedSlide = currentPresentation.append(
    sourceSlide,
    SlidesApp.SlideLinkingMode.LINKED,
);

linkedSlide.unlink();

linkedSlide.getSourcePresentationId();  // returns null
linkedSlide.getSourceSlideObjectId();   // returns null
linkedSlide
    .getSlideLinkingMode();  // returns SlidesApp.SlideLinkingMode.NOT_LINKED

授權

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

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