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日运行
参考文献
- )
- )