onChange仅在A3包含数据时才运行-Google Apps脚本/Google表格 [英] onChange to Run ONLY if A3 has data - Google Apps Script / Google Sheets

查看:47
本文介绍了onChange仅在A3包含数据时才运行-Google Apps脚本/Google表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让此脚本仅在看到A3中的数据时才运行.数据正从另一张纸传到此纸上.我尝试了onChange,但是当新数据到达"Top Up Needed"时,它不会触发.将onchange添加到项目触发器中,但仍不运行脚本.

I am trying to get this script to only run if is sees data in A3. the data is coming to this sheet from another sheet. I tried the onChange but it wouldnt trigger when the new data arrived in "Top Up Needed". add the onchange to the project triggers but still doesnt run script.

function TopUpNeeded() {

  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.setActiveSheet(spreadsheet.getSheetByName('TOP UP NEEDED'), true);
  var sheet = spreadsheet.getSheetByName('TOP UP NEEDED');
  sheet.getRange('J3').activate().setFormula('=QUERY({\'SKU & Qty\'!$A$3:$C},"SELECT * WHERE Col1 MATCHES \'" & JOIN("|",FILTER(I2:I, NOT(ISBLANK(I2:I)))) & "\' ")');

}  

在我的代码上方也尝试了此代码,但效果不佳.

also tried this code above my code,but no good.

  function onChange() {
    var sheet = SpreadsheetApp.getActive();
    ScriptApp.newTrigger("TopUpNeeded")
     .forSpreadsheet(sheet)
     .onChange()
     .create();
  }

预先感谢

推荐答案

onChange 不运行,请参见 IMPORTRANGE

您可以将该公式粘贴到需要充值"工作表的单元格"A3"中

You can paste into cell "A3" of sheet "Top Up Needed" the formula

IMPORTRANGE(spreadsheet_url,range_string)

指定要填充单元格内容的电子表格和范围.

specifying the spreadsheet and range that is expected to populate the cell content.

在这种情况下,每次 A3 的内容更新时,您的第一个函数将在 onChange 触发器上触发.

In this case your first function will fire on onChange trigger each time the content of A3 updates.

这篇关于onChange仅在A3包含数据时才运行-Google Apps脚本/Google表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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