簡報更新生命週期
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Presentation 物件的生命週期有三個主要階段:開啟、編輯和儲存。
開啟簡報
使用 Slides 服務時,第一步是載入簡報。SlidesApp.openById() 和 SlidesApp.getActivePresentation() 等方法會載入現有的 Google 簡報,而 SlidesApp.create() 則會建立新簡報。這些方法會傳回 Presentation 物件,代表載入的簡報。
簡報開啟後,就不會再收到協作者的任何更新。簡報通常會開啟儲存在雲端硬碟中的最新版本。不過,如果指令碼與簡報繫結,系統會載入與隨附 Google 簡報編輯器相同版本的簡報。
修改簡報
簡報開啟後,指令碼就能讀取及修改簡報內容。指令碼對簡報所做的任何變更,都會在指令碼執行期間反映在後續的讀取和修改作業中。
正在儲存變更
對簡報進行變更後,系統會在指令碼執行完畢時,或在呼叫 Presentation.saveAndClose() 時,一次儲存所有變更。儲存變更後,系統會非同步將變更傳播至使用者的編輯器,就像變更是由協作者所做一樣。
使用 Presentation.saveAndClose()
關閉簡報後,可以使用簡報載入方法重新開啟簡報進行編輯。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-31 (世界標準時間)。
[null,null,["上次更新時間: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."]]