我在作業表“第 2 節”中運行的函式 (clearRowContents) 將清除串列中任何選中項 (col H) 以及復選框本身 (col G) 的內容和驗證。然后將對剩余的未選中框和串列項進行排序,以清除由 clearRowContents 函式剛剛創建的任何空白行。此功能按測驗作業。
但是,如果沒有選中任何專案(col G == false)并且按下“清除”按鈕,我怎么能彈出一條訊息讓用戶知道他們必須首先選中專案旁邊的框,然后按下按鈕從串列中清除其內容?我試圖弄清楚如何為 clearItemMessage 函式撰寫腳本。
此外,出于撰寫腳本的目的,此作業表將被多次復制,以針對不同主題創建各種驗證選單......每張作業表將是手冊中的不同“章節”,具有自己獨特的一組下拉選單(在 MASTER DROPDOWN 中)標簽)。
表格鏈接:https ://docs.google.com/spreadsheets/d/1ZdlJdhA0ZJOIwLA9dw5-y5v1FyLfRSywjmQ543EwMFQ/edit?usp=sharing
代碼:
function clearItemMessage(){
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var checkboxRange = ss.getRangeList("$G$11:$G$25").getValues();
if (checkboxRange == true){
clearRowContents (col);
} else (Browser.msgBox("To delete items, select the box next to the items and then press the delete button."));
}
function clearRowContents (col){ // col is the index of the column to check for checkbox being true
var col = 7; //col G
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var data = ss.getDataRange().getValues();
//Format font & size
var sheetFont = ss.getRange("A:Z");
var boxFont = ss.getRange("$G$11:$G$25");
var listFont = ss.getRange("$H$11:$H$25");
sheetFont.setFontFamily("Montserrat");
boxFont.setFontSize(8)
.setFontColor("#434343")
.setBackground("#ffffff");
listFont.setFontSize(12)
.setFontColor("#434343")
.setBackground("#ffffff");
//clear 'true' data validations
var deleteRanges = data.reduce(function(ar, e, i) {
if (e[col - 1] === true) {
return ar.concat(["H" (i 1), "G" (i 1)]);
}
return ar;
}, []);
if (deleteRanges.length > 0) {
ss.getRangeList(deleteRanges).clearContent().clearDataValidations();
}
//sort based on checkbox value
var range = ss.getRange("$G$11:$H$25");
range.sort({column: 7, ascending: false});
}
uj5u.com熱心網友回復:
在您的情況下,如何修改clearItemMessage()如下?
修改后的腳本:
function clearItemMessage(){
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var checkboxes = ss.getRange("$G$11:$G$25").getValues();
if (checkboxes.filter(([g]) => g === true).length > 0){ // or if (checkboxes.some(([g]) => g === true)) {
clearRowContents();
} else {
Browser.msgBox("To delete items, select the box next to the items and then press the delete button.");
}
}
- 從你的問題,我理解了你的
clearRowContents作品。所以我建議修改clearItemMessage. - 在您的
clearRowContents,var col = 7中使用。所以我認為function clearRowContents (col){可以修改為function clearRowContents (){.
參考:
- 篩選()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/416331.html
標籤:
