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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.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,我正在谷歌表单上创建预算。我有两张一月份的表格(标题为一月总结和一月交易)。我正在尝试创建一个脚本,该脚本将在每个月初自动复制这些工作表,并更改当月的工作表名称。我不知道如何做到这一点,因为我是新的编码-有人有想法吗 function duplicateAndRenameSheet() { const prefix="Copy of ";//add in front of new name const postfix= ' ' + Utilities.formatDa

我正在谷歌表单上创建预算。我有两张一月份的表格(标题为一月总结和一月交易)。我正在尝试创建一个脚本,该脚本将在每个月初自动复制这些工作表,并更改当月的工作表名称。我不知道如何做到这一点,因为我是新的编码-有人有想法吗

function duplicateAndRenameSheet() {
  const prefix="Copy of ";//add in front of new name
  const postfix= ' ' + Utilities.formatDate(new Date(),Session.getScriptTimeZone,"E yyMMdd:HHmmss");//add to back of new name
  const ss=SpreadsheetApp.getActive();
  const sh=ss.getActiveSheet();
  let name=sh.getName();//active sheets name
  let nsh=ss.insertSheet({template:sh});//inserts a new sheet that's a copy of the active sheet
  nsh.setName(prefix + name + postfix);//renames the new sheet
}

只需在应用程序脚本中使用时间驱动的可安装触发器,即可实现您想要的功能。

至于复印这两张纸,以下方法可能会对您有所帮助:

  • copyTo(电子表格)
    -这将允许您将工作表复制到电子表格
在您的情况下,由于要复制两张图纸,因此必须对每张图纸使用上述方法

  • setName(name)
    -这将允许您更改工作表的名称
由于您希望获取当前月份,因此解决方案是获取当前日期,然后使用
getMonth

至于触发器,您可以创建一个如下所示的触发器:

function createTrigger() {
    ScriptApp.newTrigger('copySheets')
         .timeBased()
         .onMonthDay(1)
         .atHour(9)
         .create();
    }
}
上述功能基于
复印纸
功能创建一个基于时间的触发器(假设这是复制工作表的功能),并将在每月1日运行

参考文献
  • )

  • )