简体   繁体   English

Google脚本-插入具有多个范围的工作表

[英]Google Script — Insert sheet with multiple ranges

I have a google spreadsheet (link below) that covers a single month, then I'm inserting a sheet for the next month with only a few of the ranges as carry over data. 我有一个Google电子表格(下面的链接),涵盖了一个月,然后我要插入下个月的表格,其中仅保留少数范围作为结转数据。

https://docs.google.com/spreadsheets/d/12zJnE1J5zbnArqMUeFfq2Kk5zvyqxXA0Tgp4Y7Efzes/edit?usp=sharing https://docs.google.com/spreadsheets/d/12zJnE1J5zbnArqMUeFfq2Kk5zvyqxXA0Tgp4Y7Efzes/edit?usp=sharing

What I would to do is insert multiple ranges to different ranges, so that namestat would be placed in C3:U4 and carryover would be placed in C17:C18, date (+7) in B5, etc. 我要做的是将多个范围插入不同的范围,以便将namestat放置在C3:U4中,并将结转放置在C17:C18中,将日期(+7)放置在B5中,等等。

function TDCopyV3() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var s = ss.getActiveSheet();
  var sheetName = ss.getName();
  var namestat = ss.getRange("C3:U4").getValues();
  var carryover = ss.getRange("C17:U18").getValues();
  var date = ss.getRange("B13").getValue();
  var templateSheet = ss.getSheetByName('Template1');
  ss.insertSheet(sheetName +1, 0, {template: templateSheet}).getRange(3,3,namestat.length,namestat[0].length).setValues(namestat);
}

This is where I'm getting stuck, as I can't seem to find anything on inserting multiple partial ranges. 这就是我被困住的地方,因为在插入多个局部范围时似乎找不到任何东西。 I've attempted chaining another getRange and setData, but that only results in a error. 我尝试链接另一个getRange和setData,但这只会导致错误。

ss.insertSheet(sheetName +1, 0, {template: templateSheet}).getRange(3,3,namestat.length,namestat[0].length).setValues(namestat).getRange(3,25,carryover.length,carryover[0].length).setValues(carryover);

Try this. 尝试这个。 You have to reference the inserted shee to set its values: 您必须参考插入的shee才能设置其值:

function TDCopyV3() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var s = ss.getSheetByName("May 2014");
  var sheetName = ss.getName();
  var namestat = s.getRange("C3:U4").getValues();
  var carryover = s.getRange("C17:U18").getValues();
  var date = s.getRange("B13").getValue();
  var templateSheet = ss.getSheetByName('Template1');
  ss.insertSheet(sheetName +1, 0, {template: templateSheet})
  var shnew =ss.getSheetByName("Copy of HoursDemo1")
  var shnewVal=  shnew.getRange(3,3,namestat.length,namestat[0].length).getValues()
  shnew.getRange(3,3,namestat.length,namestat[0].length).setValues(namestat)
  shnew.getRange(17,3,carryover.length,19).setValues(carryover);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Google Apps脚本中定义多个范围 - Define multiple ranges in Google Apps Script 如何在Google Apps脚本中为Google电子表格创建具有多个范围的图表 - How to create a chart with multiple ranges in google apps script for google spreadsheets 做多个SUMIFS-Google表格脚本编辑器 - Doing multiple SUMIFS - Google Sheet Script Editor Google Sheet Script - 多个 getRange 循环 - Google Sheet Script - Multiple getRange looping 使用Google脚本重新排列工作表上的多列 - Rearrange multiple columns on sheet with Google script 有没有办法可以同时使用应用程序脚本更新多个不连续的谷歌工作表范围? (使用 SpreadsheetApp 不是工作表 api) - is there a way I can update multiple non-contiguous google sheet ranges using apps script all at the same time? (using SpreadsheetApp not sheets api) 无法从Google Apps脚本的多个工作表中获取范围 - Cannot get ranges from multiple sheets in google apps script Google脚本根据单元格值或日期范围添加多行 - Google Script adding multiple lines based on cell value or date ranges 如何使用脚本获取保存在一张谷歌表中的所有命名范围的列表? - How to get list of all named ranges saved in one google sheet with script? 谷歌表脚本中的正则表达式 - Regex in Google sheet script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM