且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

跨电子表格(而非库)共享的 Google 电子表格脚本

更新时间:2022-01-24 22:24:34

也许您所要求的只是一种将主脚本中的内容准确复制到电子表格副本中的所有脚本的方法它替换了他们的代码并跳过了引用库的需要,但我会提供我对库设置如何工作的印象......

Maybe what what you're asking for is just a way to copy exactly what's in a master script over to all of your scripts that are inside the spreadsheet copies so that it replaces their code and skips over the need to reference a library, but I'll offer my impression on how the library setup works...

我认为将该库添加到电子表格的唯一方法是创建一个该电子表格的新脚本

the only way I see to add that library to a spreadsheet is to create a new script for that spreadsheet

当您复制已经包含库引用脚本的电子表格时,它会保留在新副本中.因此,在创建了一个要复制的电子表格模板后,您不必再创建任何新脚本.

When you make a copy of a spreadsheet that already has a script with a library reference, it'll stay in with the new copy. So, you shouldn't have to create any new scripts after you've created one spreadsheet template to copy.

那个电子表格模板应该有一个对主脚本的库引用.母版不需要在工作表内,您不应该复制原始/母版脚本.

That one spreadsheet template should have a library reference to the master script. The master doesn't need to be inside a sheet and you shouldn't be copying the original / master script.

所以,我们有:1个主脚本1 个电子表格模板,其中有一个引用主文件的脚本,然后是 模板副本,如您所愿.

So, we have: 1 master script, 1 spreadsheet template that has a script that references the master, then as many copies of the template as you want.

现在,当您设置库参考时,您可以选择将其连接到开发模式下的电子表格模板.这将允许对主脚本中现有功能的任何更改立即影响模板副本(除非首先需要授权).如果您有这种方式,您可能需要先在主脚本的副本中测试您的更改.另一种选择是关闭开发模式,让模板副本的用户手动更新每个脚本中的库版本(除非有我不知道的自动版本更新系统).

Now when you setup the library reference, you have the option to connect it in the spreadsheet template in dev mode. This will allow any changes to existing functions in the master script to instantly affect the template copies (unless authorization is first needed). If you have it this way, you will might want to test out your changes in a copy of the master script first. The other option is to keep dev mode turned off and have users of the template copies manually update their library version inside each of their scripts (unless there's an automatic version updating system I don't know about).

这个设置仍然没有解决向主脚本添加一个全新函数的问题,但每个模板副本都需要引用该函数.也许有人可以对此发表评论或提供单独的答案.

This setup still doesn't solve the issue of adding a completely new function to the master script that each template copy needs to reference though. Maybe some one can comment or provide a separate answer to that.

[更新:3/15/2015]因此,将附加组件发布到 Chrome 网上应用店可以让您安装附加组件一次,并将其显示在您的所有工作表/文档/表单中,我相信这是 OP 最初需要的.推出新版本会更新所有使用它的 Google 文档.

[Update: 3/15/2015] So publishing an Add-on to the Chrome Web store lets you install an Add-on once and have it appear in all your Sheets / Docs / Forms which I believe was what was originally needed for OP. Pushing new versions out updates all Google docs that use it.

https://developers.google.com/apps-script/add-ons/