Class PropertiesService
Properties 服务
允许脚本以键值对的形式存储简单数据,范围限定为一个脚本、一个脚本的用户或使用某个插件的一个文档。属性无法在脚本之间共享。如需详细了解何时使用每种类型的媒体资源,请参阅媒体资源服务指南。
// 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
- 一个仅脚本的当前用户可以访问的属性存储
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-12-22。
[null,null,["最后更新时间 (UTC):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"]]