简体   繁体   English

如何从另一个项目运行谷歌应用程序脚本功能

[英]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: 您有两种选择:

  1. Publish your scripts as libraries and subscribe to each in each other of your script projects. 将脚本发布为库并订阅脚本项目中的每个脚本。
  2. Publish your scripts as web apps with specific functions as individual pseudo webhooks. 将您的脚本发布为具有特定功能的Web应用程序,作为单独的伪webhook。 Sort of like a distributed API. 有点像分布式API。

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: 文档:

  1. Publish your scripts as a library 将脚本发布为库
  2. Running apps script as an endpoint 将应用程序脚本作为端点运行

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

  • functionNameinScriptB = the name of the function you want to call in Script B functionNameinScriptB =要在脚本B中调用的函数的名称

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google App脚本:从另一个脚本中运行脚本吗? - Google App Script: Run script from within another script? 如何从另一个 Google App 脚本执行 Google App Script API 函数? - How to Execute Google App Script API Function from another Google App Script? 从同一项目中的另一个文件运行 Google Apps 脚本 - Run a Google Apps Script from another file within the same project 如何从Google OAuth 2.0 Playground运行Google App Script功能| 来电者没有权限 - How to run Google App Script function from Google OAuth 2.0 Playground | The caller does not have permission 从Google应用脚本中的下拉列表值运行一个函数 - Run a function from dropdownlist value in Google app script 如何获得Google App脚本警报响应以运行其他功能? - How to get an google app script alert response to run different function? 如何从 Javascript/Google App 脚本中的另一个函数调用数组 - How do I call an array from another function in Javascript/ Google App script Google Apps脚本如何从另一个项目中删除触发器 - Google apps script how to delete a trigger from another project 将谷歌脚本项目从电子表格复制到另一个 - Copy a google script project from a Spreadsheet to another Google 表格 - 如何从 iOS 应用程序运行脚本? - Google Sheets - How to run a script from iOS app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM