If var isnumber, for script

后端 未结 3 991
执念已碎
执念已碎 2020-12-31 05:45

I need to run a script which contains the logic: If isNumber, Then DoSomething.

I\'ve run other such if then tests such as if blank, and if cell contains \"

3条回答
  •  长情又很酷
    2020-12-31 06:03

    Google Apps Script could use most of the JavaScript methods and operators.

    One alternative to check if an object is a number is to use typeof.

    The following code will return the type of the value of the cell specified by the reference.

    function typeofcellvalue(reference) {
      var ss = SpreadsheetApp.getActive();
      var rng = ss.getRange(reference);
      var value = rng.getValue();
      return typeof value;
    }
    

    Example of use as a custom function

    =typeofcellvalue("A1")
    

    If cell A1

    • has a number, the result will be number.
    • is empty, the result will be string.

提交回复
热议问题