[英]Clear cell google sheet script
I have a sheet on googlesheet where there is a lot of line and column.我在 googlesheet 上有一张工作表,其中有很多行和列。
I want clear the cell where there is the value 0 in the column B.我想清除 B 列中值为 0 的单元格。
I wrote this code but it doesn't work, I'm not an expert of javascript :|我写了这段代码,但它不起作用,我不是 javascript 专家:|
function clean0() {
var sheet = SpreadsheetApp.getActiveSheet();
var data = sheet.getDataRange().getDisplayValues();
if(data == "0"){
sheet.getRange('B:B').clearContent();
}
}
Where is my mistake?我的错误在哪里?
Thanks for help :)感谢帮助 :)
You want to clear the cell content for the cells of column B which has the value of "0".您想清除 B 列值为“0”的单元格的单元格内容。 If my understanding is correct, how about this modification?如果我的理解是正确的,这个修改怎么样? I think that there are several answers for your situation.我认为对于您的情况有几种答案。 So please think of this as one of them.因此,请将此视为其中之一。
function clean0() {
var sheet = SpreadsheetApp.getActiveSheet();
var data = sheet.getRange('B:B').getDisplayValues();
var range = [];
data.forEach(function(e, i){
if (e[0] == "0") range.push("B" + (i + 1));
});
sheet.getRangeList(range).clearContent();
}
If I misunderstand your question, I'm sorry.如果我误解了你的问题,我很抱歉。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.