簡報作業
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
您可以使用 Google 簡報 API 建立簡報檔案及管理現有檔案。
本頁的範例說明如何使用 presentations.batchUpdate
方法,執行一些常見的網頁呈現作業。
這些範例以 HTTP 要求的形式呈現,因此不限語言。如要瞭解如何使用 Google API 用戶端程式庫,以不同語言實作批次更新,請參閱下列指南:
建立簡報
下列程式碼範例說明如何建立名為「My New Presentation」的空白簡報檔案:presentations.create
您也可以使用 Google Drive API files.create
方法,指定 application/vnd.google-apps.presentation
做為 MIME 類型,建立空白簡報檔案。
以下是建立簡報的要求通訊協定:
POST https://slides.googleapis.com/v1/presentations
{
"title": "My New Presentation"
}
列出現有簡報檔案
Slides API 不提供擷取簡報清單的方法,但 Drive API 提供這項功能。下方的 files.list
方法會使用欄位遮罩,從雲端硬碟傳回簡報檔案清單,其中包含檔案 ID、檔案名稱和開啟檔案的連結。要求也會將 application/vnd.google-apps.presentation
指定為 MIME 類型。
以下是列出現有簡報檔案的要求通訊協定:
GET https://www.googleapis.com/drive/v3/files?q="mimeType=application/vnd.google-apps.presentation"&fields=files(id,name,webViewLink)
這項要求的回應結構如下:
{
"files": [
{
"id": "abcdefghijklmnopqrstuvwxyz0123456789",
"name": "Project Vision",
"webViewLink": "https://docs.google.com/a/google.com/presentation/d/abcdefghijklmnopqrstuvwxyz0123456789/edit?usp=drivesdk"
},
{
"id": "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
"name": "Untitled Presentation",
"webViewLink": "https://docs.google.com/a/google.com/presentation/d/ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/edit?usp=drivesdk"
},
...
]
}
在整份簡報中取代文字
以下
presentations.batchUpdate
程式碼範例說明如何使用 ReplaceAllTextRequest
方法,在 PRESENTATION_ID 指定的簡報中取代文字。您可以從簡報網址找出簡報 ID 的值。
字串「Gizmo Corp.」的所有例項都會替換為「Gadget Inc.」。包括文字方塊和其他形狀中的文字、投影片上的文字,以及母片中的文字。在本例中,文字替代作業會區分大小寫,方法是將 matchCase
設為 true
。
以下是要求通訊協定,可取代整份簡報中的文字:
POST https://slides.googleapis.com/v1/presentations/PRESENTATION_ID:batchUpdate
{
"requests": [
{
"replaceAllText": {
"containsText": {
"text": "Gizmo Corp.",
"matchCase": true
},
"replaceText": "Gadget Inc."
}
}
]
}
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-29 (世界標準時間)。
[null,null,["上次更新時間:2025-08-29 (世界標準時間)。"],[],[],null,["# Presentation operations\n\nThe Google Slides API lets you create presentation files and manage existing ones.\nThe examples on this page show some common page presentation operations using\nthe\n[`presentations.batchUpdate`](/workspace/slides/api/reference/rest/v1/presentations/batchUpdate)\nmethod.\n\nThese examples are presented as HTTP requests to be language neutral. To learn\nhow to implement a batch update in different languages using the Google API\nclient libraries, see the following guides:\n\n- [Create and manage presentations](/workspace/slides/api/guides/presentations#create_a_blank_presentation)\n- [Search for files and folders](/workspace/drive/api/guides/search-files#specific)\n- [Merge data into a presentation](/workspace/slides/api/guides/merge#example)\n\nCreate a presentation\n---------------------\n\nThe following\n[`presentations.create`](/workspace/slides/api/reference/rest/v1/presentations/create)\ncode sample shows how to creates a blank presentation file entitled \"My New\nPresentation\".\n\nIt's also possible to create blank presentation files using the Google Drive API\n[`files.create`](/workspace/drive/api/reference/rest/v3/files/create) method by\nspecifying `application/vnd.google-apps.presentation` as the\n[MIME type](/workspace/drive/api/guides/mime-types).\n\nThe following is the request protocol to create a presentation: \n\n```\nPOST https://slides.googleapis.com/v1/presentations\n``` \n\n```text\n{\n \"title\": \"My New Presentation\"\n}\n```\n\nList existing presentation files\n--------------------------------\n\nThe Slides API doesn't provide a method for retrieving a list of\npresentations but the\n[Drive API](/workspace/drive/api/guides/about-sdk) does. The\n[`files.list`](/workspace/drive/api/reference/rest/v3/files/list) method\n(presented below) uses [field masks](/workspace/slides/api/guides/field-masks)\nto return a list of presentation files from your Drive, with the\nfile ID, filename, and a link for opening the file. The request also specifies\n`application/vnd.google-apps.presentation` as the\n[MIME type](/workspace/drive/api/guides/mime-types).\n\nThe following is the request protocol to list existing presentation files: \n\n```\nGET https://www.googleapis.com/drive/v3/files?q=\"mimeType=application/vnd.google-apps.presentation\"&fields=files(id,name,webViewLink)\n```\n\nThe [response](/workspace/drive/api/reference/rest/v3/files/list#response-body)\nto this request has the following structure: \n\n```text\n{\n \"files\": [\n {\n \"id\": \"abcdefghijklmnopqrstuvwxyz0123456789\",\n \"name\": \"Project Vision\",\n \"webViewLink\": \"https://docs.google.com/a/google.com/presentation/d/abcdefghijklmnopqrstuvwxyz0123456789/edit?usp=drivesdk\"\n },\n {\n \"id\": \"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\",\n \"name\": \"Untitled Presentation\",\n \"webViewLink\": \"https://docs.google.com/a/google.com/presentation/d/ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/edit?usp=drivesdk\"\n },\n ...\n ]\n}\n```\n\nReplace text throughout a presentation\n--------------------------------------\n\nThe following\n[`presentations.batchUpdate`](/workspace/slides/api/reference/rest/v1/presentations/batchUpdate)\ncode sample shows how to use the\n[`ReplaceAllTextRequest`](/workspace/slides/api/reference/rest/v1/presentations/request#ReplaceAllTextRequest)\nmethod to replace text throughout the presentation specified by the\n\u003cvar translate=\"no\"\u003ePRESENTATION_ID\u003c/var\u003e. You can discover the value for the\n[presentation ID](/workspace/slides/api/guides/overview#the_structure_of_a_presentation)\nfrom the presentation URL.\n\nEvery instance of the string \"Gizmo Corp.\" is replaced with the text \"Gadget\nInc.\" This includes text in text boxes and other shapes, on slides, and within\nmasters. In this instance, the text replacement is case-sensitive by setting\n[`matchCase`](/workspace/slides/api/reference/rest/v1/presentations/request#SubstringMatchCriteria)\nto `true`.\n\nThe following is the request protocol to replace text throughout a presentation: \n\n```\nPOST https://slides.googleapis.com/v1/presentations/PRESENTATION_ID:batchUpdate\n``` \n\n```text\n{\n \"requests\": [\n {\n \"replaceAllText\": {\n \"containsText\": {\n \"text\": \"Gizmo Corp.\",\n \"matchCase\": true\n },\n \"replaceText\": \"Gadget Inc.\"\n }\n }\n ]\n}\n```"]]