简体   繁体   English

基于模板创建新的 Google Sheet 并将数据从 Master Sheet 导出到新创建的表

[英]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.

相关问题 从母版工作表创建工作表 - Creating sheets with from master sheet 将数据从工作表移动到工作表Google工作表 - move data from sheet to sheet google sheets 将基于单元格值的行数据复制到 Google 表格中的新工作表 - Copy row data based on cell value to new sheet in Google Sheets 从母版工作表的最后一行复制数据,并将其粘贴到Google工作表中另一工作表的特定单元格 - Copy data from last row of master sheet and paste it in specific cells in another sheet in google sheets 将新创建的Google工作表设置为活动工作表 - set newly created google sheet as the active sheet 在Google Apps脚本中,是否有一种方法可以基于表单数据创建新标签,然后将数据从多个工作表复制到该新创建的标签中? - In Google Apps Scripts, is there a way to create new tabs based on form data, then copy data into that newly created tab from multiple sheets? Google 脚本创建新的工作表文件并将其移动到特定文件夹然后将活动工作表中的内容和 2 个标签复制到新创建的文件 - Google script Create new sheet file and move it to a specific folder Then copy the contents and 2 tabs from the active sheet to the newly created file 基于选中框的Google表格编辑表 - Google Sheets editing sheet based off of checkmark boxes 从母版向多个 Google 表格推送更新 - Push Updates To Multiple Google Sheets From Master Sheet 根据Google工作表中的缺失数据创建表单 - Creating a form based upon missing data from google sheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM