Function 在谷歌表格中用删除线识别单元格
我试图在google工作表上计算一些东西(((带删除线的单元格)/(列中的总单元格))*100),我是google脚本编辑器的新手。 脚本1:Function 在谷歌表格中用删除线识别单元格,function,google-apps-script,google-sheets,strikethrough,Function,Google Apps Script,Google Sheets,Strikethrough,我试图在google工作表上计算一些东西(((带删除线的单元格)/(列中的总单元格))*100),我是google脚本编辑器的新手。 脚本1: function countStrike(range) { var count = 0; SpreadsheetApp.getActiveSheet() .getRange(range) .getFontLines() .reduce(function (a, b) { return a.c
function countStrike(range) {
var count = 0;
SpreadsheetApp.getActiveSheet()
.getRange(range)
.getFontLines()
.reduce(function (a, b) {
return a.concat(b);
})
.forEach(function (el) {
if (el === "line-through") {
count++
}
});
return count;}
脚本1错误:
“找不到范围。(第9行)”
脚本2:
function countStrike(B2:B50) {
var count = 0;
SpreadsheetApp.getActiveSheet()
.getRange()
.getFontLines()
.reduce(function (a, b) {
return a.concat(b);
})
.forEach(function (el) {
if (el === "line-through") {
count++
}
});
return count;
}
脚本2错误:
“缺少形式参数。(第1行)”
我能问一下你的问题吗?脚本中的第9行在哪里?您如何称呼countStrike(range)<代码>电子表格应用程序.getActiveSheet().getRange(range).getFontLines()正确。因此,我认为调用
countStrike(range)
时,range可能会出现错误。第9行是“.forEach(function(el){”行。我不确定应该如何定义它,因为我的目标是能够定义函数中的范围,比如SUM(B5:B20)如何工作,您希望将其用作自定义函数,如=countStrike(“B5:B20”)
。我的理解正确吗?但我不希望每次都必须更改代码中的范围。我希望能够从电子表格中进行更改,自定义。@JoeDoe当您运行countStrike(范围)时
使用脚本编辑器时,会发生错误。因为未给出范围
。因此,例如,当您想要运行它时,请将函数run(){Logger.log(countStrike(“B2:B50”)}
放入脚本编辑器,然后运行run()
。