将参数传递给mouseCallback

时间:2011-09-22 14:18:05

标签: javascript google-sheets

我有一个简单但有问题的问题。

有没有办法,使用谷歌脚本向mouseCallback发送参数? 这里解释了一些例子,但是每次在函数中写入单元格。

我希望这个单元格随着时间的推移而改变,我需要将一个字符串传递给回调。

此作品

function foo() {
  var doc = SpreadsheetApp.getActiveSpreadsheet();
  var app = UiApp.createApplication();

  var button = app.createButton('submit');
  app.add(button);

  var handler = app.createServerClickHandler('b');
  button.addClickHandler(handler);

  doc.show(app);
}

function b() {
  var doc = SpreadsheetApp.getActiveSpreadsheet();
  var cell = doc.getRange('a1');
  cell.setValue(Number(cell.getValue()) + 1);

  var app = UiApp.getActiveApplication();
  app.close();
  // The following line is REQUIRED for the widget to actually close.
  return app;
}

我想要这样的东西

function foo() {
  var doc = SpreadsheetApp.getActiveSpreadsheet();
  var app = UiApp.createApplication();

  var button = app.createButton('submit');
  app.add(button);

  var value = 'A1';
  var handler = app.createServerClickHandler('b', value);
  button.addClickHandler(handler);

  doc.show(app);
}

function b(value) {
  var doc = SpreadsheetApp.getActiveSpreadsheet();
  var cell = doc.getRange(value);
  cell.setValue(Number(cell.getValue()) + 1);

  var app = UiApp.getActiveApplication();
  app.close();
  // The following line is REQUIRED for the widget to actually close.
  return app;
}

任何人都可以帮助我吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

这里有这个问题的答案:

Thansk去google论坛用户:)

http://www.google.com/support/forum/p/apps-script/thread?fid=2ef3693fc9aee1050004ad903de88dd4&hl=en