如何检查细胞中是否有东西 [英] how to check whether cell has anything in it

查看:46
本文介绍了如何检查细胞中是否有东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含6列的电子表格,前3行保留用于标题.一旦用户在该行的5个单元格中输入信息,他将执行一个脚本来发送电子邮件.发送电子邮件后,第6个单元格将显示EMAIL_SENT.

I have a spreadsheet with 6 columns, the first 3 rows are reserved for heading. Once the user enters information in 5 cells of the row he would execute a script that would send an email. The 6th cell is for showing EMAIL_SENT after the email was sent.

我遇到的问题是错误检查,我不希望用户在没有所有五个单元格都包含数据的情况下发送电子邮件.

What i have problem with is error checking, i dont want the user to send an email without all five cells having data in it.

function Email() {

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var range = sheet.getDataRange();
range = range.offset(3, 0, range.getNumRows()-3);

range.getValues().forEach( function( recipient, index, data ){

        if (recepient[0] == ""){Browser.msgBox("No data in column A");}
        .
        .         
        .    
});
}

我希望我可以检查单元格是否等于零,空白并通知,但这不起作用.

I was hoping i could check if the cell is equal to nothing, blank and notify but this is not working.

非常感谢您的帮助. :)

Your help is much appreciated. :)

推荐答案

您正在使用的功能有效,但无法调用浏览器服务...

The function you are using works but is not able to call the Browser service...

如果将其替换为Logger.log,则会得到预期的结果.

If you replace with a Logger.log you get the result as expected.

  range.getValues().forEach( function( recipient, index, data ){
    if (recipient[0] == ""){Logger.log("Missing data in column A");}
  });

恕我直言,毕竟它比在我的UI中显示许多弹出窗口要方便得多...

IMHO, it is after all far more convenient than getting many popups appearing in my UI...

下面的代码将在col A中不存在数据时显示警告

below is a code that will show a warning when no data is present in col A

  range = range.offset(3, 0, range.getNumRows()-3);
  var result=false;
  range.getValues().forEach( function( recipient, index, data ){
    if (recipient[0] == ""){result="Missing data in column A"}
  });
  if(result){Browser.msgBox(result);  return };

这篇关于如何检查细胞中是否有东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆