如何在基于觸發器的谷歌腳本中自動洗掉帶有多個作業表的行,我使用了這個腳本并且它有效,但我希望這個腳本能夠一次使用兩個或多個標簽表,而當前腳本只使用一個標簽頁。如何在 getSheetByName 中使用多個標簽頁?誰能幫我?因為每次我在這里問沒有人回答,這是我的第三個問題,前兩個沒有人幫助回答。有什么問題我不知道。
function acraCleanup() {
var SPREADSHEET_KEY = "AABVGGHJGFGDFG4GFD65GHDF56HGFHG53";
// Replace with your spreadsheet Key,
//you can find this by trying to share the Spread sheet
// and getting the key between the "=" and the "&"
var SHEET_NAME = "Sheet 1"; //Sheet 1 unless you changed the sheet name
var rowsToKeep = 1000; //Will keep bottom 1000 Rows
var sheet = SpreadsheetApp.openById(SPREADSHEET_KEY).getSheetByName(SHEET_NAME);
var rows = sheet.getLastRow();
var numToDelete = rows – rowsToKeep -1;
if (numToDelete > 0) sheet.deleteRows(2, numToDelete);
}
uj5u.com熱心網友回復:
嘗試
function acraCleanup() {
var SPREADSHEET_KEY = "AABVGGHJGFGDFG4GFD65GHDF56HGFHG53";
var rowsToKeep = 1000; //Will keep bottom 1000 Rows
const list = ['SheetX','SheetY'];
var ss = SpreadsheetApp.openById(SPREADSHEET_KEY)
ss.getSheets().filter(sh => list.indexOf(sh.getName()) != -1).forEach(function (sheet){
var rows = sheet.getLastRow();
var numToDelete = rows - rowsToKeep - 1;
if (numToDelete > 0) sheet.deleteRows(2, numToDelete);
})
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/443758.html
標籤:javascript 谷歌应用脚本 谷歌表格 电子表格
上一篇:每個唯一值的逗號分隔數字的總和
