【问题标题】:Local Storage in Google Apps Scripts (Forms and Sheets)Google Apps 脚本(表单和表格)中的本地存储
【发布时间】:2021-07-06 11:58:05
【问题描述】:

我想在我的本地存储(浏览器)中设置一些值并将其用于 表格。

例如: 我打开一个表格,它在我的 LS 中看到我的密钥告诉我们我来自 X 公司。 我填写表格,并根据我的密钥将其发送到该公司的特定表格 如果它没有看到任何键,它会打开一个提示,提示您填写公司名称(键)。

以下内容:

const company = localStorage.key[0].value;

if (! company ) {
  //prompt message
  //set prompt result as key
} else if (company === "X") {
  googleSheetUrl = 'https://docs.google.com/spreadsheets/d/.../';
} else if (company === "Y") {
  googleSheetUrl = 'https://docs.google.com/spreadsheets/d/.../';
}
  1. 这是(不)推荐的做法吗?
  2. 我应该如何处理这个问题?

【问题讨论】:

  • 它只在客户端可用。我一直在 chrome sn-ps 中使用它。我不完全确定您尝试做什么,但我可能会使用 PropertiesService。
  • 这是什么上下文?工作区插件?
  • 这将是一个工作区跟踪器,但对于多个组织,所以我考虑制作一个脚本来从用户那里寻找一个键(或者如果没有,则设置一个)作为选择器在需要将信息发送到的工作表 url 上。

标签: forms google-apps-script google-sheets local-storage google-forms


【解决方案1】:

localStorage 仅在浏览器中可用。 Apps 脚本在 Google 服务器中执行,因此不可用。 Apps Script 已经有了替代方案:Properties Service。这允许有一个脚本、用户或文档的字符串值字典。在这种情况下,您需要一个用户属性。使用方法如下:

const userProperties = PropertiesService.getUserProperties()
userProperties.setProperty('company', companyName)

参考文献

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多