从 localStorage 获取数据(谷歌脚本)

FLi*_*ter 3 javascript google-sheets google-apps-script

在我的谷歌电子表格应用程序中,我在一个函数中将一些参数保存在 localStorage 中。在另一个函数中我需要检索它们。当然,我可以创建无模式对话框或侧边栏,什么时候是我的html代码和js,但是第二个函数只刷新当前工作表,所以我不需要UI。我也知道,服务器端无法访问本地存储。这是我的抽象代码:

server.gs

function menuItemClicked()
{
    // when we click on item in addon menu, this called
    // and load 'client.html'
}

function refreshCurrentSheet(params)
{
    // called by 'client.html'
    // do something else with params...
}
Run Code Online (Sandbox Code Playgroud)

client.html

<script type="text/javascript">
    google.script.run.refreshCurrentSheet( localStorage.getItem('var') );
</script>
Run Code Online (Sandbox Code Playgroud)

我在 API 中没有找到答案,该怎么做(

问题:如何在没有可见 UI 的情况下加载 html 并执行 js?

PS 将这些参数保存在服务器端的缓存中并不是一个解决方案,因为我经常在客户端中使用和更改它们

Ant*_*iev 6

您可以使用属性服务或缓存服务。两者都提供 localStorage 功能,允许您存储键值对(仅限字符串类型)。如果您想在函数调用之间保留数据,缓存可能是最好的选择

有关缓存服务的更多信息 https://developers.google.com/apps-script/reference/cache/

有关属性服务的更多信息 https://developers.google.com/apps-script/reference/properties/