如何在 Google Sheet 中隐藏 Google App Script 功能?

问题描述 投票:0回答:2

在 Google app 脚本项目中,我创建了一个用于获取 token 的函数。在项目中完美运行。但我注意到我的功能Google表格可见。它返回Google工作表单元格中的令牌。我已附上图像。

--> 你可以看到我定义了 getTokenFromMacro 函数来获取 token

-->在这里您可以看到我的功能google工作表单元格中可见

那么,我如何才能

隐藏我的令牌,使其不对其他人可见,或者如何隐藏我的功能,使其在Google表格功能中不可见?

我在

javascript.html 文件中使用了 getTokenFromMacro

这个问题有什么解决办法吗?

google-apps-script google-sheets google-sheets-api add-on custom-function
2个回答
3
投票
Google Apps 脚本允许您指定该函数是否是私有的或者是否可以通过 Google 表格访问:

自定义函数的名称不能以下划线 (_) 结尾,这表示 Apps 脚本中的私有函数。

您可以将函数声明更改为:

function getTokenFromMacro_() { const scriptProperties = PropertiesService.getScriptProperties(); const token = scriptProperties.getProperty('API_TOKEN') return token; }
尝试将其用作自定义函数时会出现错误

Unknown function: 'getTokenFromMacro_'.


参考:

    自定义函数指南 -
  • 命名

0
投票
请尝试一下:从 HTML 中,您将调用一个公共函数 - nameYouWant() - 该函数将调用一个私有函数 - getTokenFromMacro_()

在天然气中

function nameYouWant(){ return getTokenFromMacro_() }
HTML 中

google.script.run .withFailure... .withSuccess... .withUser... .nameYouWant()
    
© www.soinside.com 2019 - 2024. All rights reserved.