SpreadSheet被另一个脚本更改时运行Google Apps脚本 [英] Google Apps Script run when SpreadSheet is change by another Script

查看:124
本文介绍了SpreadSheet被另一个脚本更改时运行Google Apps脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这个脚本需要更新数据,只要有一个更改为SpreadSheet。只需触发onChange即可。



然而,SpreadSheet本身也被另一个函数更新,而且当更改是由另一个AppScript引起时,onChange似乎不会被触发。 b
$ b

是否有另一种方法可以实现我所描述的功能?



下面的代码,谢谢

  var ss = SpreadsheetApp.openById(tqwJk280I1O_yW5oNX9nLQA); 

函数doGet(){
var app = UiApp.createApplication();
var masPanel = app.createFlowPanel()。setId(panel);
var number = parseInt(ss.getRange(A1)。getValue());
masPanel.add(app.createLabel(number));
masPanel.add(app.createFlowPanel()。add(app.createFormPanel()
.add(app.createFlowPanel()
.add(app.createSubmitButton(Plus!)) )));

app.add(masPanel);

返回应用;


函数doPost()
{
var num = parseInt(ss.getRange(A1)。getValue())+ 1;
ss.getRange(A1)。setValue(num);


函数onChange()
{
ss.getRange(A2)。setValue(hahaha);
var app = UiApp.createApplication();
app.remove(app.getElementById(panel))
var masPanel = app.createFlowPanel()。setId(panel);
var number = parseInt(ss.getRange(A1)。getValue());
masPanel.add(app.createLabel(number));
masPanel.add(app.createFlowPanel()。add(app.createFormPanel()
.add(app.createFlowPanel()
.add(app.createSubmitButton(Plus!)) )));

app.add(masPanel);

返回应用;


解决方案 onChange()函数不会引用用户界面。例如,如果有多个拥有相同用户界面的人打开,应该更新哪一个?

因此,解决您的问题的方法是让您的UI代码定期轮询电子表格,并在电子表格发生变化时更新UI。为此,您可以使用未公开的 addTimer()方法。
查看此 SO问题&回答一个很好的例子


I'm trying to write a script that display row value in a SpreadSheet file using UiApp.

And this script will need to update the data whenever there is a change to the SpreadSheet. This would normally be simple with just Trigger onChange.

However, the SpreadSheet itself is also updated by another function, and it seem that onChange is not triggered when the changes made are caused by another AppScript.

Is there an alternative way to achieve what I described?

Code below, thanks

    var ss = SpreadsheetApp.openById("tqwJk280I1O_yW5oNX9nLQA");

function doGet() {
  var app = UiApp.createApplication();
  var masPanel = app.createFlowPanel().setId("panel");
  var number = parseInt(ss.getRange("A1").getValue());
  masPanel.add(app.createLabel(number));
  masPanel.add(app.createFlowPanel().add(app.createFormPanel()
           .add(app.createFlowPanel()
           .add(app.createSubmitButton("Plus!")))));

  app.add(masPanel);

  return app;
}

function doPost()
{
  var num = parseInt(ss.getRange("A1").getValue()) + 1;
  ss.getRange("A1").setValue(num);
}

function onChange()
{
  ss.getRange("A2").setValue("hahaha");
  var app = UiApp.createApplication();
  app.remove(app.getElementById("panel"))
  var masPanel = app.createFlowPanel().setId("panel");
  var number = parseInt(ss.getRange("A1").getValue());
  masPanel.add(app.createLabel(number));
  masPanel.add(app.createFlowPanel().add(app.createFormPanel()
           .add(app.createFlowPanel()
           .add(app.createSubmitButton("Plus!")))));

  app.add(masPanel);

  return app;
}

解决方案

The onChange() function will not have reference to the UI. For example, if there are multiple people who have the same UI open, which one should be updated ?

So, the solution to your problem is for your UI code to poll the spreadsheet regularly and update the UI if the spreadsheet has changed. To do so, you can use the undocumented addTimer() method. See this SO question & answer for a nice example

这篇关于SpreadSheet被另一个脚本更改时运行Google Apps脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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