Google apps script 跨电子表格共享的Google电子表格脚本(非库)
我已经对这个问题做了大量的搜索,我认为问题在于所有答案都会导致一个需要您创建一个库的解决方案。然后,我看到的将该库添加到电子表格的唯一方法是为该电子表格创建一个新脚本并将其包括在内 我想要的是: 包含一个主脚本的一组电子表格。每次更新脚本时,它们都会更新以使用最新的脚本 我所拥有的: 15份电子表格,均包含原始脚本的副本。原始脚本已更改,现在看来我必须编辑每个复制的电子表格中存在的名为Google apps script 跨电子表格共享的Google电子表格脚本(非库),google-apps-script,google-sheets,Google Apps Script,Google Sheets,我已经对这个问题做了大量的搜索,我认为问题在于所有答案都会导致一个需要您创建一个库的解决方案。然后,我看到的将该库添加到电子表格的唯一方法是为该电子表格创建一个新脚本并将其包括在内 我想要的是: 包含一个主脚本的一组电子表格。每次更新脚本时,它们都会更新以使用最新的脚本 我所拥有的: 15份电子表格,均包含原始脚本的副本。原始脚本已更改,现在看来我必须编辑每个复制的电子表格中存在的名为Copy of myScriptName的脚本 我所做的: 我创建了第一个电子表格,并在脚本编辑器中创建的项目中
Copy of myScriptName
的脚本
我所做的:
我创建了第一个电子表格,并在脚本编辑器中创建的项目中编写了脚本。工作得很好。然后,我为公司的每个部门制作了14份电子表格供使用
我如何在任何单独的电子表格之外共享脚本并管理它?考虑到所有人都在寻找同一个答案,我肯定错过了一些东西。我只是不知道如何使它成为一个库来解决我的用例
谢谢
我看不出这有什么帮助,但根据评论的要求,这里是脚本:
function createRollupTable() {
//Return if:
// There is only the account code parameters passed in with no quarterly info
// If the length of the account code parameters passed is empty
if(arguments.length <= 1 || !arguments[0] || arguments[0].length <= 0) {
return "";
}
var rollupTable = new Array();
var fullListAccountCodes = arguments[0];
//The first column of output is the full list of account codes for all the quarters
rollupTable[0] = fullListAccountCodes;
//Array to keep the YTD total for each account code
var yearlyAccountCostOutput = new Array(fullListAccountCodes.length);
//Iterate over all the quarters that were passed in
for(var i=1;i<arguments.length;i++) {
//This array should be set to the total length of the available account codes
var quarterlyRollupCostOutput = new Array(fullListAccountCodes.length);
var quarterlyBreakdown = arguments[i];
var quarterIndexCounter = 0;
var quarterTotalCost = 0;
//Iterate over all the account codes
for(var j=0;j<fullListAccountCodes.length && quarterIndexCounter<quarterlyBreakdown.length;j++) {
//Find the one that matches the current account code for this quarter
if(fullListAccountCodes[j] == quarterlyBreakdown[quarterIndexCounter][0]) {
//Set the index of the output based on the full list so they align
quarterlyRollupCostOutput[j] = quarterlyBreakdown[quarterIndexCounter][1];
//Add this cost to the running total for the quarter
quarterTotalCost += quarterlyBreakdown[quarterIndexCounter][1];
//Add the total amount for the yearly rollup for that account code
if(yearlyAccountCostOutput[j]) {
yearlyAccountCostOutput[j] += quarterlyBreakdown[quarterIndexCounter][1];
} else {
yearlyAccountCostOutput[j] = quarterlyBreakdown[quarterIndexCounter][1];
}
//Increment the counter so we search for the next account code in the quarter
quarterIndexCounter++;
}
}
rollupTable[i] = quarterlyRollupCostOutput;
//Add a blank row in the results for spacing
rollupTable[i].push("");
//Add the quarterly total cost
rollupTable[i].push(quarterTotalCost);
}
//Add a blank row for spacing
rollupTable[0].push("");
//Google spreadsheet forces you to pad with non breaking spaces, no right align option available
var spaces = "";
var numSpaces = 66;
for(var i=0;i<numSpaces;i++){spaces+=String.fromCharCode(160);};
//Add a row for the Totals
rollupTable[0].push(spaces + "Totals:");
//Add the YTD column
rollupTable.push(yearlyAccountCostOutput);
return rollupTable;
}
函数createRollupTable(){
//如果:
//只有传入的帐户代码参数,没有季度信息
//如果传递的帐户代码参数的长度为空
如果(arguments.length也许你想要的只是一种将主脚本中的内容准确复制到电子表格副本中的所有脚本中的方法,这样它就可以替换它们的代码并跳过引用库的需要,但是我将提供关于库设置如何工作的印象
我看到的将该库添加到电子表格的唯一方法是创建一个
该电子表格的新脚本
当你复制一个已经有一个带有库引用的脚本的电子表格时,它将保留在新的副本中。因此,在创建一个要复制的电子表格模板之后,你不必创建任何新的脚本
一个电子表格模板应该有一个主脚本的库引用。主脚本不需要在工作表中,也不应该复制原始/主脚本
所以,我们有:,它有一个引用主控的脚本,然后你想要多少就有多少
现在,当您引用时,您可以选择在开发模式下在电子表格模板中连接它。这将允许对主脚本中现有函数的任何更改立即影响模板副本(除非首先需要授权)。如果采用这种方式,您可能希望首先在主脚本副本中测试更改。另一个选项是关闭开发模式,让模板副本的用户在每个脚本中手动更新其库版本(除非有自动版本更新系统我不知道)
但是,此设置仍然无法解决向主脚本添加每个模板副本都需要引用的全新函数的问题。也许有人可以对此进行评论或提供单独的答案
[更新:3/15/2015]
因此,在Chrome网上商店发布一个附加组件可以让你安装一次附加组件,并让它出现在你的所有工作表/文档/表单中,我相信这是OP最初需要的。推出新版本会更新所有使用它的Google文档
你能在你的问题中发布你的主脚本中的函数吗?我想我想知道是什么触发了你副本中的函数,但我会发布我想的设置。该死,所有这些电子表格的设置都必须重做。啊!好吧,你的方法很有意义。谢谢你的帮助,布莱恩。真的吗你肯定知道,你只需要更改现有功能中的代码,还是最终会在主脚本中添加其他功能?是的,我肯定知道。在每个季度结束时,我将收集每个部门主管的反馈,并对布局、数据处理等进行调整。我想管理t他在一个位置,并将其推送到每个部门负责人的个人电子表格中。模板方法很有意义,只是不幸我在复制方法上浪费了很多时间。感谢您的帮助。您能允许我编辑您在解决方案中编写的通用脚本的访问权限吗?请求已发送。