我对googledocs和脚本非常陌生,可以帮助我。
我需要一个脚本:
我有一次尝试,但它只做了部分工作......但似乎没有正常工作。这就是我所拥有的:
function myFunction() {
SpreadsheetApp.getActiveSpreadsheet().duplicateActiveSheet();
SpreadsheetApp.getActiveSpreadsheet().renameActiveSheet("New Sheet");
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// Rows start at "1" - this will delete the first two rows
sheet.deleteRows(2, 100);
}
非常感谢你的阅读!
答案 0 :(得分:0)
这里的技巧是跟踪电子表格是“活动的” - 因为你想要复制第一张表,你需要确保第一张表是“活动的”。 (你不能只是假设它是。)
重复第一张纸后,新纸张将处于“有效”状态。这很有用,因为您想要执行的某些操作只能在“活动”工作表上运行。
function myFunction() {
// Make the first sheet active in the active workbook
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.setActiveSheet(ss.getSheets()[0]);
// duplicate the 1st sheet (1st in order)
var newSheet = SpreadsheetApp.getActiveSpreadsheet().duplicateActiveSheet();
// place the duplicate in the first positions
ss.moveActiveSheet(1);
// rename the duplicate to current date
newSheet.setName((new Date()).toDateString());
// delete all the rows below the first one in the duplicate file (e.g. 2nd to 300th row)
var lastRow = newSheet.getLastRow();
newSheet.deleteRows(2, lastRow-1);
}