Google Spreadheets Scripts: check if cell is empty

前端 未结 3 1045
無奈伤痛
無奈伤痛 2020-12-06 04:14

I want to input a variable in a cell only if the cell is empty. The if statement, however, does not work. Any advice?

var ss=SpreadsheetApp.getActiveSpreadsh         


        
3条回答
  •  情话喂你
    2020-12-06 04:59

    No need to extact the value to determine if the cell is empty. Google Spreadsheet API already has a method for this: Range - isBlank method

    var cell = r.getCell(rws-1, 10);
    
    if (cell.isBlank()) {
        cell.setValue("foo");
    }
    

提交回复
热议问题