如何将项目从下拉列表添加到flex表?

时间:2012-11-18 06:07:40

标签: google-apps-script

我想使用下面的按钮将下拉列表中的所选项目添加到flex表中。有人可以编辑我现有的代码以使其工作或向我显示我需要使用的处理程序吗?

我希望将项目放在flex表的第一列和第一行中。

链接到包含脚本的电子表格:here

//Create button that adds items to flex table   
    var button = app.createButton('+');
PS:我是航空航天工程师而不是程序员。我还有很多东西需要学习。

1 个答案:

答案 0 :(得分:1)

以下是一些示例代码,展示了如何执行您想要的操作。基本上,创建一个将列表框作为回调元素的处理程序。然后,在处理程序函数中,使用e.parameter.listBoxName引用活动列表框条目以使用它。

function doGet() {
  var app = UiApp.createApplication();
  var listBox = app.createListBox();
  listBox.addItem("item 1").addItem("item 2").addItem("item 3").setName("myListBox");

  var handler = app.createServerHandler("buttonHandler");
  // pass the listbox into the handler function as a parameter
  handler.addCallbackElement(listBox);

  var table = app.createFlexTable().setId("myTable");

  var button = app.createButton("+", handler);
  app.add(listBox);
  app.add(button);
  app.add(table);
  return app;
}

function buttonHandler(e) {
  var app = UiApp.getActiveApplication();
  app.getElementById("myTable").insertRow(0).insertCell( 0, 0).setText( 0, 0, e.parameter.myListBox);
  return app;
}