【问题标题】:Google Spreadsheet: TypeError Cannot find function indexOf in object 0 (Line 7 in Code.gs)Google 电子表格:TypeError 在对象 0 中找不到函数 indexOf(Code.gs 中的第 7 行)
【发布时间】:2015-01-15 15:44:53
【问题描述】:

所以我试图让我的代码工作。它确实……有时。

代码是:

function getAntallVakter(tabell, navn) {

  var antall = 0;

  for(i = 0; i<tabell.length;i++){
    for(j=0;j<tabell[i].length;j++){
      if(tabell[i][j].indexOf(navn)>-1){
        antall += 1;
      }
    }
  }
  return antall;
}

当我测试它时它确实有效,但是当我在需要此脚本的电子表格上使用它时,它不适用于给定范围。它确实适用于其他范围。在特定范围内它不起作用我收到了一些错误:

TypeError 在对象 0 中找不到函数 indexOf(Code.gs 中的第 7 行)
TypeError 在 2015 年 1 月 1 日星期四 00:00:00 GMT+0100 (CET) 中找不到函数 indexOf。

感谢我得到的任何帮助。

【问题讨论】:

    标签: javascript google-sheets typeerror


    【解决方案1】:

    我不敢相信我完全忘记检查单元格是否是字符串的天气。

    添加行

    var text = tabell[i][j].toString();
    

    在 if 语句之前解决了所有问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-27
      • 2018-03-31
      相关资源
      最近更新 更多