屬性物件可做為存取使用者、文件或指令碼屬性的介面。具體的屬性類型取決於指令碼呼叫的 Properties
的三種方法:Properties
、Properties
或 Properties
。屬性無法在指令碼間共用。如要進一步瞭解資源類型,請參閱資源服務指南。
方法
方法 | 傳回類型 | 簡短說明 |
---|---|---|
delete | Properties | 刪除目前 Properties 儲存庫中的所有屬性。 |
delete | Properties | 在目前的 Properties 商店中刪除具有指定鍵的資源。 |
get | String[] | 取得目前 Properties 儲存庫中的所有鍵。 |
get | Object | 取得目前 Properties 儲存庫中的所有鍵/值組合副本。 |
get | String | 在目前的 Properties 儲存庫中,取得與指定鍵相關聯的值,如果不存在此鍵,則傳回 null 。 |
set | Properties | 在目前的 Properties 儲存庫中,設定指定物件的所有鍵/值組合。 |
set | Properties | 在目前的 Properties 儲存庫中,設定指定物件的所有鍵/值組合,並視需要刪除儲存庫中的所有其他屬性。 |
set | Properties | 在目前的 Properties 儲存庫中設定指定的鍵/值組合。 |
內容詳盡的說明文件
delete All Properties()
刪除目前 Properties
儲存庫中的所有屬性。
// Deletes all user properties. const userProperties = PropertiesService.getUserProperties(); userProperties.deleteAllProperties();
回攻員
Properties
:這個 Properties
儲存器,用於鏈結
delete Property(key)
在目前的 Properties
商店中刪除具有指定鍵的資源。
// Deletes the user property 'nickname'. const userProperties = PropertiesService.getUserProperties(); userProperties.deleteProperty('nickname');
參數
名稱 | 類型 | 說明 |
---|---|---|
key | String | 要刪除的資源鍵 |
回攻員
Properties
:這個 Properties
儲存器,用於鏈結
get Keys()
取得目前 Properties
儲存庫中的所有鍵。
// Sets several properties, then logs the value of each key. const scriptProperties = PropertiesService.getScriptProperties(); scriptProperties.setProperties({ cow: 'moo', sheep: 'baa', chicken: 'cluck', }); const keys = scriptProperties.getKeys(); Logger.log('Animals known:'); for (let i = 0; i < keys.length; i++) { Logger.log(keys[i]); }
回攻員
String[]
:目前 Properties
儲存庫中的所有鍵陣列
get Properties()
取得目前 Properties
儲存庫中的所有鍵/值組合副本。請注意,傳回的物件並非商店的即時檢視畫面。因此,變更傳回物件的屬性不會自動更新儲存空間中的屬性,反之亦然。
// Sets several script properties, then retrieves them and logs them. const scriptProperties = PropertiesService.getScriptProperties(); scriptProperties.setProperties({ cow: 'moo', sheep: 'baa', chicken: 'cluck', }); const animalSounds = scriptProperties.getProperties(); // Logs: // A chicken goes cluck! // A cow goes moo! // A sheep goes baa! for (const kind in animalSounds) { Logger.log('A %s goes %s!', kind, animalSounds[kind]); }
回攻員
Object
:目前 Properties
儲存庫中的所有鍵/值組合副本
get Property(key)
在目前的 Properties
儲存庫中,取得與指定鍵相關聯的值,如果不存在此鍵,則傳回 null
。
// Gets the user property 'nickname'. const userProperties = PropertiesService.getUserProperties(); const nickname = userProperties.getProperty('nickname'); Logger.log(nickname);
參數
名稱 | 類型 | 說明 |
---|---|---|
key | String | 要擷取的屬性值鍵 |
回攻員
String
:與目前 Properties
商店中指定鍵相關聯的值
set Properties(properties)
在目前的 Properties
儲存庫中,設定指定物件的所有鍵/值組合。
// Sets multiple user properties at once. const userProperties = PropertiesService.getUserProperties(); const newProperties = { nickname: 'Bob', region: 'US', language: 'EN' }; userProperties.setProperties(newProperties);
參數
名稱 | 類型 | 說明 |
---|---|---|
properties | Object | 包含要設定的鍵/值組合物件 |
回攻員
Properties
:這個 Properties
儲存器,用於鏈結
set Properties(properties, deleteAllOthers)
在目前的 Properties
儲存庫中,設定指定物件的所有鍵/值組合,並視需要刪除儲存庫中的所有其他屬性。
// Sets multiple user properties at once while deleting all other user // properties. const userProperties = PropertiesService.getUserProperties(); const newProperties = { nickname: 'Bob', region: 'US', language: 'EN' }; userProperties.setProperties(newProperties, true);
參數
名稱 | 類型 | 說明 |
---|---|---|
properties | Object | 包含要設定的鍵/值組合物件 |
delete | Boolean | true 可刪除屬性物件中的所有其他鍵/值組合;false 則不會刪除 |
回攻員
Properties
:這個 Properties
儲存器,用於鏈結
set Property(key, value)
在目前的 Properties
儲存庫中設定指定的鍵/值組合。
// Sets the user property 'nickname' to 'Bobby'. const userProperties = PropertiesService.getUserProperties(); userProperties.setProperty('nickname', 'Bobby');
參數
名稱 | 類型 | 說明 |
---|---|---|
key | String | 屬性的鍵 |
value | String | 要與鍵建立關聯的值 |
回攻員
Properties
:這個 Properties
儲存器,用於鏈結