展示操作
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
借助 Google Slides API,您可以创建演示文稿文件并管理现有文件。
本页面的示例展示了使用 presentations.batchUpdate
方法的一些常见网页呈现操作。
这些示例以 HTTP 请求的形式呈现,不涉及具体语言。如需了解如何使用 Google API 客户端库以不同语言实现批量更新,请参阅以下指南:
创建演示文稿
以下 presentations.create
代码示例展示了如何创建名为“My New Presentation”的空白演示文件。
您还可以通过指定 application/vnd.google-apps.presentation
作为 MIME 类型,使用 Google Drive API files.create
方法创建空白演示文稿文件。
以下是用于创建演示的请求协议:
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."
}
}
]
}
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-29。
[null,null,["最后更新时间 (UTC):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```"]]