Google脚本查找单元格是否为空白-isBlank函数不起作用

时间:2018-09-12 07:34:04

标签: google-sheets-api google-sheets-query

这是我的代码。我仅在单元格不为空的情况下才尝试执行代码。由于我们没有isBlank i的内置函数,尽管我使用它来用预定义值填充空单元格。但这确实

for (var i = 2, k = 2, j = 2, s = 2; i<lastrow && k>0; s++){
   var range = sheet.getRange(i,1);
   var company = range.getValue();
   var range = sheet.getRange(i,2);
   var description = range.getValue();
   var range = sheet.getRange(i,3);
   var priority = range.getValue();
      var range = sheet.getRange(i,4);
   var urgency = range.getValue();
      var range = sheet.getRange(i,5);
   var impact = range.getValue();
      var range = sheet.getRange(i,6);
   var requester = range.getValue();
      var range = sheet.getRange(i,7);
   var status = range.getValue();
      var range = sheet.getRange(i,8);
   var subject = range.getValue();
   var pay="{\"helpdesk_ticket\":{ \"description\":\""+description+"\", \"subject\":\""+subject+"\",\"email\":\""+requester+"\",\"priority\":\""+priority+"\",\"status\":\""+status+"\",\"impact\":\""+impact+"\", \"urgency\":\""+urgency+"\"   }}";
   if(description.isBlank()){
   var url="https://"+purl+"/helpdesk/tickets.json"; 
   var options = {
                 "payload": pay,
                 "method": "POST",
                 "muteHttpExceptions": true,

错误消息: see error screenshot

2 个答案:

答案 0 :(得分:1)

因为您获得了一个值,它不再是一个单元格obj,所以它是一个字符串,并且要检查string是否为0,我们使用函数长度,因此在您的情况下应该是

...
if(description.length > 0)
...

答案 1 :(得分:0)

isBlank()是类Range的方法。但是,您尝试在description上调用它,它不是类Range的对象,而是NumberBooleanDateString,如here

所述