【问题标题】:GAS simple script not workingGAS 简单脚本不起作用
【发布时间】:2013-02-16 16:30:38
【问题描述】:

根据 Google 的说法,我有一个“按部就班”的脚本,但它不起作用。

function capacityAlert() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("counts");
var currentValue = sheet.getRange("D2:D13").getValues();
Logger.log('currentValue = '+currentValue);
var nRows = currentValue.length;
for(var i=0;i<nRows;i++)
{
    //Logger.log(currentValue[i][0]);
    Logger.log('row '+i+' col[0] = '+currentValue[i][0]);
    if(currentValue[i][0]=="true")
    {
      Browser.msgBox("Capacity Reached");
        //MailApp.sendEmail("dave@davelalande.com","Capacity Reached","Capacity Reached, \nplease check the sheet and remove the date.");
    }  
}
}

日志是这样写的。

currentValue = false,false,false,false,false,false,false,false,false,false,false,true
row 0 col[0] = false
row 1 col[0] = false
row 2 col[0] = false
row 3 col[0] = false
row 4 col[0] = false
row 5 col[0] = false
row 6 col[0] = false
row 7 col[0] = false
row 8 col[0] = false
row 9 col[0] = false
row 10 col[0] = false
row 11 col[0] = true

它不是邮寄的,所以我试图创建一个弹出窗口,只是为了看看脚本是否工作。我已经关闭并使用正在运行的三行弹出脚本测试了我的弹出窗口,所以我知道弹出窗口正在运行。

调试是空白的?我错过了什么?

感谢您提供的任何帮助。

戴夫

【问题讨论】:

  • 您可以在记录器中使用 typeOf() 检查 currentValue[I][0] 的类型吗?不确定它是一个字符串...如果不是,在比较的第一项添加 .toString() 。
  • 当您在电子表格中输入“true”时,是否会自动将其全部变为大写字母?
  • 你可以试试:if(currentValue[i][0]) if the values are boolean.
  • 抱歉 typeof 拼写错误,语法是 Logger.log(typeof(currentValue[i][0])) ,你可能会得到 'boolean' 这意味着 Michael 是对的,你可以在你的条件下省略 ==true,这就是布尔逻辑的工作原理...这也是为什么它在您的工作表中以大写字母显示的原因(所以 Phil 也是对的 ;-) 最后它不是一个字符串(所以我也是对的 ^^)所以每个人都很高兴 ...
  • 开心真好! Serge,你如何在 cmets 中突出显示?更容易理解。

标签: loops google-apps-script


【解决方案1】:

这对我有用。

 if(currentValue[i][0]==true)

感谢 ScampMichael、Serge 和 Phil 一直以来的帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多