Class PropertiesService
資源Service允許指令碼將簡單資料儲存在鍵/值組合中,範圍限定為一個指令碼、一個指令碼的使用者,或使用外掛程式的一個文件。屬性無法在指令碼間共用。如要進一步瞭解何時使用每種屬性類型,請參閱「屬性」服務指南。
// Sets three properties of different types.
const documentProperties = PropertiesService.getDocumentProperties();
const scriptProperties = PropertiesService.getScriptProperties();
const userProperties = PropertiesService.getUserProperties();
documentProperties.setProperty('DAYS_TO_FETCH', '5');
scriptProperties.setProperty(
'SERVER_URL',
'http://www.example.com/MyWeatherService/',
);
userProperties.setProperty('DISPLAY_UNITS', 'metric');
內容詳盡的說明文件
getDocumentProperties()
取得屬性儲存庫 (僅限此指令碼),所有使用者都能在開啟的文件、試算表或表單中存取。只有在指令碼以外掛程式形式發布及執行,或繫結至 Google 檔案類型時,才能使用這項功能。如果無法取得文件屬性,這個方法會傳回 null
。指令碼建立的文件屬性無法在該指令碼之外存取,即使是其他指令碼存取相同文件也一樣。
回攻員
Properties
:這個指令碼專用的屬性儲存庫,目前文件的所有使用者都能存取;如果指令碼不是外掛程式,或未繫結至 Google Workspace 檔案,則為 null
getScriptProperties()
取得所有使用者都能存取的資源儲存庫,但僅限於這個指令碼。
回攻員
Properties
:所有指令碼使用者都能存取的屬性儲存庫
getUserProperties()
取得只有目前使用者可存取的屬性儲存庫,且只能在這個指令碼中存取。
回攻員
Properties
:只有指令碼的目前使用者才能存取的屬性儲存庫
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-12-22 (世界標準時間)。
[null,null,["上次更新時間:2024-12-22 (世界標準時間)。"],[[["The Properties Service lets Apps Script store simple data as key-value pairs, with different scopes for scripts, users, and documents."],["It offers three methods to access properties: `getDocumentProperties()`, `getScriptProperties()`, and `getUserProperties()`."],["`getDocumentProperties()` provides property storage accessible to all users within a specific document, spreadsheet, or form where the script is running."],["`getScriptProperties()` allows storing properties accessible to all users, but only within the context of the current script."],["`getUserProperties()` provides a property store specific to the current user and accessible only within the current script."]]],["The `PropertiesService` stores data in key-value pairs, accessible via `getDocumentProperties`, `getScriptProperties`, and `getUserProperties`. `getDocumentProperties` stores data within a specific document, accessible to all users. `getScriptProperties` stores data within a script, accessible to all users. `getUserProperties` stores data for a single user within a script. The example code demonstrates setting properties using each method: `setProperty`. Each method returns a `Properties` object, which is a property store.\n"]]