gpt4 book ai didi

google-apps-script - 在多个 *.gs 文件中组织电子表格代码 - 甚至可能吗?

转载 作者:行者123 更新时间:2023-12-03 13:25:43 27 4
gpt4 key购买 nike

我正在尝试在多个脚本文件中组织电子表格的代码。在脚本编辑器中,我可以创建任意数量的 *.gs 文件,但我不知道如何访问将在另一个脚本中定义的代码。

我想要实现的简单示例:

代码.gs:

function onEdit(){
myFunctionFromLibrary_gs();
}

图书馆.gs:
function myFunctionFromLibrary_gs(){
Browser.msgBox("hi there");
}

onEdit() 显然是由触发器调用的。
如果不修改,这将导致运行时错误,说明

myFunctionFromLibrary_gs TypeError: is not a function, it is undefined.



那么我该如何完成这项工作,或者目前不支持?

提前感谢您的帮助。

最佳答案

是的,这是可能的。

  1. You are not limited to a single server Code.gs file. You can spread server code across multiple files for ease of development. All of the server files are loaded into the same global namespace, so use JavaScript classes when you want to provide safe encapsulation.


引用: Google Documentation - features and limitations

关于google-apps-script - 在多个 *.gs 文件中组织电子表格代码 - 甚至可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11725675/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com