Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 谷歌工作表-使重复工作表处于活动状态,并首先_Google Apps Script_Google Sheets - Fatal编程技术网

Google apps script 谷歌工作表-使重复工作表处于活动状态,并首先

Google apps script 谷歌工作表-使重复工作表处于活动状态,并首先,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我有以下脚本,它复制指定的工作表,复制并重命名为todays date function Duplicate() { var source = SpreadsheetApp.getActiveSpreadsheet(); const patternX = 'Master'; var masterX = source.getSheetByName(patternX); masterX.copyTo(source).setName(getDates()[1]).showShe

我有以下脚本,它复制指定的工作表,复制并重命名为todays date

function Duplicate() {
  
 var source = SpreadsheetApp.getActiveSpreadsheet();
 
 const patternX = 'Master';
 
 var masterX = source.getSheetByName(patternX);

 masterX.copyTo(source).setName(getDates()[1]).showSheet();
  
 masterX.hideSheet();
}
我正在努力对其进行以下修改:

  • 是否可以将复制日期自动添加到复制新工作表的单元格A1中
  • 如何激活重复工作表/将其移动到工作簿中的第一个工作表
这应该可以:

function Duplicate() {
 const source = SpreadsheetApp.getActiveSpreadsheet();
 const patternX = 'Master';
 const masterX = source.getSheetByName(patternX);
 const new_dt = getDates()[1];
 const new_sheet = masterX.copyTo(source).setName(new_dt).showSheet();
 new_sheet.getRange("A1").setValue(new_dt);
 source.setActiveSheet(new_sheet);
 source.moveActiveSheet(1);
 masterX.hideSheet();
}
这应该起作用:

function Duplicate() {
 const source = SpreadsheetApp.getActiveSpreadsheet();
 const patternX = 'Master';
 const masterX = source.getSheetByName(patternX);
 const new_dt = getDates()[1];
 const new_sheet = masterX.copyTo(source).setName(new_dt).showSheet();
 new_sheet.getRange("A1").setValue(new_dt);
 source.setActiveSheet(new_sheet);
 source.moveActiveSheet(1);
 masterX.hideSheet();
}

新的
尝试:
新的
尝试: