[英]how to run google app script function from another project
I have few sheets that have functions bound to the spreadsheet. 我有几张具有绑定到电子表格的功能的工作表。 Each spreadsheet has its own functions and uses SpreadsheetApp.getUi to run html service.
每个电子表格都有自己的功能,并使用SpreadsheetApp.getUi来运行html服务。 I would like to initiate function calls in all the sheets from a master spreadsheet project?
我想在主电子表格项目的所有工作表中启动函数调用? is it possible?
可能吗? Something like getting a handle to the spreadsheet project and run a script in that project?
比如获取电子表格项目的句柄并在该项目中运行脚本?
You have two options: 您有两种选择:
There are pros and cons of each. 各有利弊。 Neither is about maintainability really.
关于可维护性也不是真的。
The library option will afford code completion whereas the web app option will enable (if you wish) for you to run code asynchronously. 库选项将提供代码完成,而Web应用程序选项将启用(如果您愿意)您以异步方式运行代码。
Both have different speed penalties. 两者都有不同的速度惩罚。 Library enabled scripts are slower as described in the documentation.
启用库的脚本速度较慢,如文档中所述。 Web apps will be slower because of
urlfetch
latency. 由于
urlfetch
延迟,Web应用程序会变慢。
Library functions will use the runtime allowed for them in the host script, whereas web apps will extend runtime and some quotas. 库函数将使用主机脚本中允许的运行时,而Web应用程序将扩展运行时和一些配额。
Documentation: 文档:
using library seems to me is the fastest and simplest way to protect your code. 在我看来,使用库是保护代码的最快,最简单的方法。 for this you need :
为此你需要:
1 spreadsheet or any google doc containing Code - SCRIPT A 1个电子表格或任何包含代码的Google文档 - SCRIPT A.
1 stand-alone script SCRIPT B that you publish as a library. 您作为库发布的1个独立脚本SCRIPT B.
in the editor of SCRIPT A - 在SCRIPT A的编辑中 -
you add the library Key
你添加库密钥
in the SCRIPT A code you can call the function of SCRIPT B 在SCRIPT A代码中,您可以调用SCRIPT B的功能
function callFunctionOfScriptB(){ LibraryIdentifier.functionNameinScriptB() } function callFunctionOfScriptB(){LibraryIdentifier.functionNameinScriptB()}
you find LibraryIdentifier when you click on Resources + libraries in the column Identifier of the popup 当您在弹出窗口的标识符列中单击Resources + libraries时,您会找到LibraryIdentifier
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.