0
我有這些腳本單獨工作,但是當我組合它們或創建兩個不同的腳本時,只有一個會起作用。如果發現條件格式化工具讓我的電子表格陷入困境,所以我使用第一個腳本來替換該函數,並且它使所有不同。第二個腳本只是一個存檔腳本,用於將行移動到歸檔表單。無論我將誰結合起來,只有一個人會一次起作用。我已經嘗試了兩個單獨的腳本,並嘗試合併。包括更改函數的名稱。我錯過了什麼?多個OnEdit Google Scripts在同一張紙上 - 單獨工作,一起工作不太好
function onEdit(e) {
if (e) {
var ss = e.source.getActiveSheet();
var r = e.source.getActiveRange();
// E.g. status column is 2nd (B)
status = ss.getRange(r.getRow(), 2).getValue();
// Specify the range with which You want to highlight
// with some reading of API you can easily modify the range selection properties
// (e.g. to automatically select all columns)
rowRange = ss.getRange(r.getRow(),3,1,8);
// This changes font color
if (status == 'Complete') {
rowRange.setFontColor("#d3d3d3");
rowRange.setBackgroundColor("#FFFFFF");
} else if (status == 'This Week') {
rowRange.setFontColor("#000000");
rowRange.setBackgroundColor("#ACE5A2");
} else if (status == 'Next Week') {
rowRange.setFontColor("#000000");
rowRange.setBackgroundColor("#D3D8D9");
} else if (status == 'Priority') {
rowRange.setFontColor("#FFFF11");
rowRange.setBackgroundColor("#1997F6");
} else if (status == 'Late') {
rowRange.setFontColor("#D92B14");
rowRange.setBackgroundColor("#FFFFFF");
} else if (status == '') {
rowRange.setFontColor("#000000");
rowRange.setBackgroundColor("#FFFFFF");
}
}
}
function onEditArchive() {
var sheetsToWatch= ["Valley","DBWC","Genus Heart","Mutli
Run","ECM","MRE","Medella","Mitro"];
var columnNumberToWatch = 10; // column A = 1, B = 2, etc.
var valueToWatch = "Archive";
var sheetNameToMoveTheRowTo = "Archive";
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getActiveCell();
if (sheetsToWatch && range.getColumn() == columnNumberToWatch &&
range.getValue() == valueToWatch) {
var targetSheet = ss.getSheetByName(sheetNameToMoveTheRowTo);
var targetRange = targetSheet.getRange(targetSheet.getLastRow() + 1,
1);
sheet.getRange(range.getRow(), 1, 1,
sheet.getLastColumn()).moveTo(targetRange);
sheet.deleteRow(range.getRow());
}
}
請勿使用onEdit作爲要由可安裝觸發器調用的函數的名稱。這可能會導致意想不到的結果。查看[Google表格可安裝onEdit()觸發器未被授權添加日曆事件](https://stackoverflow.com/q/46721366/1595451) –