演示文稿更新的生命周期
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
演示对象的生命周期主要分为三个阶段:打开、编辑和保存。
打开演示文稿
使用 Slides 服务时,第一步是加载演示文稿。SlidesApp.openById() 和 SlidesApp.getActivePresentation() 等方法用于加载现有的 Google 幻灯片演示文稿,而 SlidesApp.create() 用于创建新的演示文稿。这些方法会返回一个表示已加载演示的 Presentation 对象。
演示文稿打开后,便不会再收到协作者的任何更新。演示文稿通常会以保存在云端硬盘中的最新版本打开。不过,如果脚本与演示文稿绑定,则该演示文稿将以与配套的 Google 幻灯片编辑器相同的版本加载。
修改演示文稿
演示文稿打开后,脚本可以读取和修改该演示文稿。脚本对演示文稿所做的任何更改都会在脚本执行期间反映在后续读取和修改中。
正在保存更改
对演示文稿进行更改后,当脚本执行完成或调用 Presentation.saveAndClose() 时,系统会一次性保存所有更改。保存更改后,这些更改会异步传播到用户的编辑器,就好像是协作者所做的更改一样。
使用 Presentation.saveAndClose()
关闭演示文稿后,可以使用演示文稿加载方法之一重新打开演示文稿以进行编辑。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eThe Slides service allows you to open existing or create new Google Slides presentations for manipulation within Apps Script.\u003c/p\u003e\n"],["\u003cp\u003eScripts can modify presentations, with changes reflected immediately within the script but saved and propagated to the editor upon script completion or explicit save.\u003c/p\u003e\n"],["\u003cp\u003eSaving changes to a presentation is done automatically at the end of script execution or manually using \u003ccode\u003ePresentation.saveAndClose()\u003c/code\u003e, after which the presentation can be reopened.\u003c/p\u003e\n"]]],[],null,["# Life cycle of a presentation update\n\nThere are three main phases in the life cycle of a\n[Presentation](/apps-script/reference/slides/presentation) object: opening,\nediting, and saving.\n\nOpening a presentation\n----------------------\n\nWhen using the Slides Service, the first step is to load a presentation. Methods\nlike [SlidesApp.openById()](/apps-script/reference/slides/slides-app#openbyidid)\nand [SlidesApp.getActivePresentation()](/apps-script/reference/slides/slides-app#getactivepresentation)\nload an existing Slides presentation, while\n[SlidesApp.create()](/apps-script/reference/slides/slides-app#createname)\ncreates a new presentation. These methods return a\n[Presentation](/apps-script/reference/slides/presentation) object that\nrepresents the loaded presentation.\n\nOnce a presentation is open, it does not receive any further updates from\ncollaborators. Presentations are usually opened at their latest version that has\nbeen saved in Drive. However, if a script is container-bound to a presentation,\nthat presentation will be loaded at the same version as the accompanying Slides\neditor.\n\nModifying a presentation\n------------------------\n\nOnce a presentation is open, a script can read and modify it. Any changes that\nthe script makes to the presentation are reflected in subsequent reads and\nmodifications for the duration of the script execution.\n\nSaving changes\n--------------\n\nAfter making changes to a presentation, the changes are saved all at once\nwhen the script execution completes, or when [Presentation.saveAndClose()](/apps-script/reference/slides/presentation#saveandclose) is\ncalled. After changes are saved, they propagate asynchronously to the\nuser's editor, as if the changes were made by a collaborator.\n\nAfter a presentation is closed using `Presentation.saveAndClose()`, it can be\nreopened for editing using one of the presentation loading methods."]]