![](/img/trans.png)
[英]Can I use a script to copy and rename a sheet in Google Sheets with the current data as the tab name?
[英]How do I make a copy of a google sheet tab and rename it
这是我的代码,我试图让 oldmonthtab 复制自己并将自己命名为 newmonthname,但我只是想不出如何让最后一部分工作。
var oldMonthName = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("X2").getRange("U4").getValue();//name for the old month, formula in X2
var newMonthName = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("X2").getRange("U3").getValue();//name for new month, formula in X2
var oldMonthTab = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(oldMonthName);//old month tab, used to be able to hide it
var destination = SpreadsheetApp.openById('1lQ10rgciG5WiUQ0uVQc1E7r7Qwd6hOkZQSaH');//chooses this spreadsheet, the ID should come from the URL of the sheet it will be copied to.
oldMonthTab.copyTo(destination).setname(newMonthTab);//makes a copy of old month and sets the name to new month```
变量newMonthTab
未定义。 用这个:
oldMonthTab.copyTo(destination).setname(newMonthName);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.