Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script Google脚本中的事件如何从元素中获取数据_Google Apps Script_Google Apps - Fatal编程技术网

Google apps script Google脚本中的事件如何从元素中获取数据

Google apps script Google脚本中的事件如何从元素中获取数据,google-apps-script,google-apps,Google Apps Script,Google Apps,问题1)当点击一个按钮时,是否可以使用类似的东西(见下面的代码) 问题2)单击标签时,是否可以使用类似的内容(请参见下面的代码) 抱歉,这可能很愚蠢,但我找不到任何合适的例子,而且似乎无法从谷歌的文档中解决这个问题,我也只是习惯了谷歌脚本。如果你有答案,我将非常感激。你离我不远。。。但距离不够近,无法让它工作 Ui元素的值在添加到处理程序的所谓回调元素中发送给处理程序函数。这个callback元素可以是一个按钮、一个标签,或者更容易的是,包含所有其他小部件的父小部件。这些“元素”位于处理函数的“

问题1)当点击一个按钮时,是否可以使用类似的东西(见下面的代码)

问题2)单击标签时,是否可以使用类似的内容(请参见下面的代码)


抱歉,这可能很愚蠢,但我找不到任何合适的例子,而且似乎无法从谷歌的文档中解决这个问题,我也只是习惯了谷歌脚本。如果你有答案,我将非常感激。

你离我不远。。。但距离不够近,无法让它工作

Ui元素的值在添加到处理程序的所谓回调元素中发送给处理程序函数。这个callback元素可以是一个按钮、一个标签,或者更容易的是,包含所有其他小部件的父小部件。这些“元素”位于处理函数的“e”中,并通过它们的名称来标识
在另一个方向,即如果需要从另一个函数修改Ui元素,则可以通过其ID(
getElementbyId()
)获取该元素,并以与在Ui定义函数中相同的方式为其赋值

我复制/粘贴另一篇文章中的示例代码来说明我所说的,您可以看到保存复选框值的
e.parameter.chkmode
,我将添加一个标签来显示相反的过程(单击按钮时文本会发生更改)

希望我足够清楚

var sh = SpreadsheetApp.getActiveSheet();
var ss = SpreadsheetApp.getActiveSpreadsheet();
//
function move() {
   var app = UiApp.createApplication().setTitle("move test")
       .setHeight(100).setWidth(400).setStyleAttribute("background-color","beige");
   var panel = app.createVerticalPanel();
   var next = app.createButton('next').setWidth('180');
   var chkmode = app.createCheckBox("moving mode (checked = up/dwn, unchecked=L/R)").setValue(false).setName('chkmode');
   var label = app.createLabel("test Label with text that will be modified on click").setId('label');
   panel.add(next).add(chkmode).add(label);
   var handler = app.createServerHandler('click').addCallbackElement(panel);
   next.addClickHandler(handler);
   app.add(panel);
   ss.show(app);
 }
//
function click(e) {
  var app = UiApp.getActiveApplication();
  var activeline = sh.getActiveRange().getRow();// get the row number of the selected cell/range
  var activecol = sh.getActiveRange().getColumn();// get the row number of the selected cell/range
  var label = app.getElementById('label');
  label.setText('You have clicked the button');
  var chkmode=e.parameter.chkmode;
  if(chkmode=="true"){
    activeline++
    }else{
      activecol++}
  var sel=sh.getRange(activeline,activecol);
  sh.setActiveSelection(sel);// make the next row active
  return app;
 }

对于UI和事件教程,我建议:

function LabelClick(e) {
  var LabelText = e.parameter.getText();
}
var sh = SpreadsheetApp.getActiveSheet();
var ss = SpreadsheetApp.getActiveSpreadsheet();
//
function move() {
   var app = UiApp.createApplication().setTitle("move test")
       .setHeight(100).setWidth(400).setStyleAttribute("background-color","beige");
   var panel = app.createVerticalPanel();
   var next = app.createButton('next').setWidth('180');
   var chkmode = app.createCheckBox("moving mode (checked = up/dwn, unchecked=L/R)").setValue(false).setName('chkmode');
   var label = app.createLabel("test Label with text that will be modified on click").setId('label');
   panel.add(next).add(chkmode).add(label);
   var handler = app.createServerHandler('click').addCallbackElement(panel);
   next.addClickHandler(handler);
   app.add(panel);
   ss.show(app);
 }
//
function click(e) {
  var app = UiApp.getActiveApplication();
  var activeline = sh.getActiveRange().getRow();// get the row number of the selected cell/range
  var activecol = sh.getActiveRange().getColumn();// get the row number of the selected cell/range
  var label = app.getElementById('label');
  label.setText('You have clicked the button');
  var chkmode=e.parameter.chkmode;
  if(chkmode=="true"){
    activeline++
    }else{
      activecol++}
  var sel=sh.getRange(activeline,activecol);
  sh.setActiveSelection(sel);// make the next row active
  return app;
 }