无法在Google文档中显示用户界面

时间:2013-09-18 08:31:35

标签: google-apps-script

我将theese脚本放入Google文档,但它什么也没做。我无法在文档中看到UI。

function demoUI() {
var myapp = UiApp.createApplication().setTitle('An improved GUI');

var mygrid = myapp.createGrid(3, 2);
mygrid.setWidget(0, 0, myapp.createLabel('Name:'));
mygrid.setWidget(0, 1, myapp.createTextBox());
mygrid.setWidget(1, 0, myapp.createLabel('Age:'));
mygrid.setWidget(1, 1, myapp.createTextBox());
mygrid.setWidget(2, 0, myapp.createLabel('City'));
mygrid.setWidget(2, 1, myapp.createTextBox());

var mybutton = myapp.createButton('Press me');
var mypanel = myapp.createVerticalPanel();
mypanel.add(mygrid);
mypanel.add(mybutton);
myapp.add(mypanel);
return myapp;
}​

2 个答案:

答案 0 :(得分:0)

您是否在Google Doc容器中操作?在这种情况下,显示ui的方法是不同的,您需要将它们放在侧边栏或对话框中,请查看此处:https://developers.google.com/apps-script/guides/docs#custom_menus_and_user_interfaces

答案 1 :(得分:0)

你应该替换:

return myapp;

由:

var ss = SpreadsheetApp.getActiveSpreadsheet();
    ss.show(myapp);

最后,您应该:

function demoUI() {
  var myapp = UiApp.createApplication().setTitle('An improved GUI');

  var mygrid = myapp.createGrid(3, 2);
  mygrid.setWidget(0, 0, myapp.createLabel('Name:'));
  mygrid.setWidget(0, 1, myapp.createTextBox());
  mygrid.setWidget(1, 0, myapp.createLabel('Age:'));
  mygrid.setWidget(1, 1, myapp.createTextBox());
  mygrid.setWidget(2, 0, myapp.createLabel('City'));
  mygrid.setWidget(2, 1, myapp.createTextBox());

  var mybutton = myapp.createButton('Press me');
  var mypanel = myapp.createVerticalPanel();
  mypanel.add(mygrid);
  mypanel.add(mybutton);
  myapp.add(mypanel);


  var ss = SpreadsheetApp.getActiveSpreadsheet();
  ss.show(myapp);
 }