允许脚本将简单数据存储到一个脚本、一个脚本的用户或一个使用插件的文档中。不能在脚本之间共享属性。如需详细了解何时使用每种类型的媒体资源,请参阅媒体资源服务指南。
// Sets three properties of different types. var documentProperties = PropertiesService.getDocumentProperties(); var scriptProperties = PropertiesService.getScriptProperties(); var userProperties = PropertiesService.getUserProperties(); documentProperties.setProperty('DAYS_TO_FETCH', '5'); scriptProperties.setProperty('SERVER_URL', 'http://www.example.com/MyWeatherService/'); userProperties.setProperty('DISPLAY_UNITS', 'metric');
方法
方法 | 返回类型 | 简介 |
---|---|---|
getDocumentProperties() | Properties | 获取所有用户均可在打开的文档、电子表格或表单中访问的属性存储区(仅限此脚本)。 |
getScriptProperties() | Properties | 获取所有用户均可访问的属性存储区,但仅限于此脚本。 |
getUserProperties() | Properties | 获取只有当前用户可以访问且仅在此脚本内访问的属性存储区。 |
详细文档
getDocumentProperties()
获取所有用户均可在打开的文档、电子表格或表单中访问的属性存储区(仅限此脚本)。仅当脚本作为插件发布和执行时,或者脚本已被绑定到 Google 文件类型时,才能使用此脚本。当文档属性不可用时,此方法会返回 null
。由某个脚本创建的文档属性无法在该脚本之外访问,即使是访问同一文档的其他脚本也无法访问。
返回
Properties
- 只有当前文档的所有用户才能访问此脚本的属性存储区,或者,如果脚本不是插件或绑定到 Google Workspace 文件,则为 null