在將幾個單元格組合成一個陣列后,我正在檢查該陣列以通過快速檢查空單元格來確認用戶沒有錯過任何輸入。它每次都能很好地作業,除非其中一些值是數字 0。當任何輸入為 0 時,它會觸發標志,要求用戶在每個單元格中輸入一個值。對于此工具,0 應該是一個可接受的值,所以我想允許它同時不允許丟失(空白)單元格。我一直在從 Apps Script 中挖掘檔案并在 StackOverflow 上搜索類似的問題,但到目前為止我還是一無所獲。
以下是我為此功能提供的代碼。
console.log(sourceVals)
const anyEmptyCell = sourceVals.findIndex(cell => cell == "");
if(anyEmptyCell !== -1){
const ui = SpreadsheetApp.getUi();
ui.alert(
"Input Incomplete",
"Please enter a value in ALL input cells before submitting",
ui.ButtonSet.OK
);
return;
uj5u.com熱心網友回復:
只需更改比較運算子:
function testie() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName("Sheet0");
const vs = sh.getRange("A1:A23").getValues().flat();
const anyEmptyCell = vs.findIndex(cell => cell === "");//just change the comparison operator
if (anyEmptyCell !== -1) {
const ui = SpreadsheetApp.getUi();
ui.alert(
"Input Incomplete",
"Please enter a value in ALL input cells before submitting",
ui.ButtonSet.OK
);
}
}
我的資料:
| 一個 | |
|---|---|
| 1 | COL1 |
| 2 | 17 |
| 3 | 14 |
| 4 | 1 |
| 5 | 19 |
| 6 | 14 |
| 7 | 1 |
| 8 | 11 |
| 9 | 3 |
| 10 | 16 |
| 11 | 0 |
| 12 | 19 |
| 13 | 8 |
| 14 | 2 |
| 15 | 15 |
| 16 | 10 |
| 17 | 19 |
| 18 | 12 |
| 19 | 2 |
| 20 | 1 |
| 21 | 11 |
| 22 | |
| 23 |
它在第 22 行的索引 21 處找到一個空單元格,并且該列中有一個零
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/524233.html
標籤:谷歌应用脚本谷歌表格
