我正在嘗試撰寫一個腳本,該腳本將根據單元格值取消選中一行中的框。例如,如果單元格 Q2 中的復選框為真,我希望將 J2、K2、L2 和 M2 中的值設定為假。但我希望它對每一行執行相同的操作,步驟 1:檢查如果Q列中的單元格為真,如果是,則將相應行的J,K,L,M的值設定為假。如果是假的,那就什么都不做。 圖片
到目前為止,我已經嘗試過:
function logDataInEveryCell() {
var range = SpreadsheetApp.getActive().getRangeByName("CheckBox");
var values = range.getValues();
// tickboxes
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Tracker');
var firstBox = SpreadsheetApp.getActiveSpreadsheet().getRangeByName('sentEmail');
var secondBox = SpreadsheetApp.getActiveSpreadsheet().getRangeByName('secondEmail');
var thirdBox = SpreadsheetApp.getActiveSpreadsheet().getRangeByName ('reminder');
var fourthBox = SpreadsheetApp.getActiveSpreadsheet().getRangeByName ('booked');
//loop to check the value of another i checkbox
values.forEach(function(row) {
var i = row.forEach(function(col) {
if ( i === true ){
//if i checkbox is ticked, set the value of these tickboxes to false, I cannot set a static coordinates for the cell as it wont read the rows bellow...
ss.getRange(firstBox).setValue(false);
ss.getRange(secondBox).setValue(false);
ss.getRange(thirdBox).setValue(false);
ss.getRange(fourthBox).setValue(false);
}
Logger.log(col);
});
});
}
但這對我不起作用,有什么想法可以解決它或我缺少什么嗎?(我使用了命名范圍)
uj5u.com熱心網友回復:
取消選中 Q 是否真實
function myfunk() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName('Tracker');
const vs = sh.getRange(2,1,sh.getLastRow() - 1, sh.getLastColumn()).getValues();
vs.forEach((r,i) => {
if(r[16]) {
sh.getRange(i 2, 10 , 1 ,4).uncheck();
}
})
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/411501.html
標籤:
