[英]Creating a new Google Sheet based off a template and exporting data from Master Sheet to newly created sheets
I'm apart of a committee at my University that allocates $90,000 of funding by reading through different requests and allocating money accordingly.我是我大学的一个委员会的一员,该委员会通过阅读不同的请求并相应地分配资金来分配 90,000 美元的资金。
We finalize the allocation by completing an NOL form that has information about how much money is allocated per different categories.我们通过填写一份 NOL 表格来完成分配,其中包含有关每个不同类别分配多少资金的信息。
All of this information is in a mastersheet.所有这些信息都在一个母版表中。 I'm looking to code a script that takes data from 250 rows on the master sheet, and turn it into 250 unique Google Sheets that have the information imported from the master sheet, along with initializing each google sheet to follow a specific template.
我正在编写一个脚本,该脚本从母版上的 250 行中获取数据,并将其转换为 250 个独特的 Google 表格,其中包含从母版导入的信息,同时初始化每个谷歌表格以遵循特定模板。
I'm stuck on the part where I create a new sheet to copy my template onto the new sheet, updating the value on the new sheet, before storing the link of the new sheet on my master document.在将新工作表的链接存储在我的主文档上之前,我被困在创建新工作表的部分,以将我的模板复制到新工作表上,更新新工作表上的值。
Is this something that Google Apps script is capable of?这是 Google Apps 脚本能够做到的吗? I'll paste my (incomplete) code.
我将粘贴我的(不完整的)代码。 Currently the links are being pasted on the master sheet, but the template is not currently imported and I get linked to a blank sheet (when it should include the template)
目前链接被粘贴到主表上,但模板当前未导入,我链接到一张空白表(当它应该包含模板时)
Also, is there an easier solution to my problem?另外,我的问题有更简单的解决方案吗? Perhaps I don't need to create a new sheet but I can add on existing sheets (I would do this but this would be 250 additional sheets)
也许我不需要创建新工作表,但我可以添加现有工作表(我会这样做,但这将是 250 张额外工作表)
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Justin's Analysis");
var range = sheet.getRange("A1:P23");
var nolSheet = ss.getSheetByName(['NOL']);
var nolTemplateRange = nolSheet.getRange("A1:J33")
var data = range.getValues();
//console.log(sheet.getMaxRows())
// data[2][15] = "Test"
// range.setValues(data)
for (i = 1; i<= 22; i++){// loop through NOL creation process through all rows of data.
var clubName = data[i][1];
var input = "NOL" + i + clubName;
console.log(input)
var ssNew = SpreadsheetApp.create(input);
var sheet = SpreadsheetApp.getActiveSheet();
// var nolSheet = ss.getSheetByName(['NOL']);
// let nolTemplateRange = nolSheet.getRange("A1: J33")
//var rangeToCopy = sheet.getRange(1, 1, sheet.getMaxRows(), 5);
nolTemplateRange.copyTo(sheet.getRange("A1:J33"));
nolSheet.copyTo(ssNew) // copies NOL into new spreadsheet
//Copy Registration
let registration = data[i][9];
let subscription = data[i][10];
let incentive = data[i][11];
let food = data[i][12];
let other = data[i][13];
let total = data[i][14];
//Copy Subscription
//Copy Incentives
//Copy Food
//Copy Supplies/Other
// grab Copy of NOL into new created sheet.
// Input values from data into new sheet
// input new sheets URL into NOL row.
data[i][15] = ssNew.getUrl();
}
range.setValues(data)
}
The issue was that you're not able to copy data from one google sheet to a different google sheet using the copy to function.问题是您无法使用复制功能将数据从一个谷歌工作表复制到另一个谷歌工作表。 You would need to use the getValues function on the first sheet before setting the values on the second sheet.
在第二张纸上设置值之前,您需要在第一张纸上使用 getValues 函数。 I found my answer from this StackOverflow Question: Copying google spreadsheet columns from one spreadsheet to another with a script
我从这个 StackOverflow 问题中找到了答案: 使用脚本将 google 电子表格列从一个电子表格复制到另一个电子表格
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.