我已经对这个问题进行了大量搜索,我认为问题在于所有答案都导致了需要您创建库的解决方案。然后,我看到将该库添加到电子表格的唯一方法是为该电子表格创建一个新脚本并将其包含在内。
我想要的:一堆都包含一个主脚本的电子表格。每次更新脚本时,它们都会更新为使用最新的脚本。
我所拥有的:15 个电子表格,都有原始脚本的副本。原始脚本已更改,现在看来我必须编辑
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;
}