Google表格 - 从动态边栏获取反馈

时间:2015-07-27 09:40:42

标签: javascript google-sheets sidebar

我在Google表格中创建了一个侧边栏,其中填充了Sheet本身的元素。它必须这样做,因为其中一些值会经常更改 - 因此,它不使用HTML。

部分代码的重要性如下:

//build the sidebar
var UIInstance=UiApp.createApplication()
  .setTitle('Please choose Plant below:')
  .setWidth(250);
//get the values over
var MaxRow=250;
var LookIn=0;
var GoHere="http://www.google.co.uk";
var L1; var L2; var L3;
for(LookIn=1;LookIn<MaxRow;LookIn++)
{
  L1=sheet.getRange("AB" + LookIn);
  L2=sheet.getRange("AC" + LookIn);
  L3=sheet.getRange("AD" + LookIn);
  if(L1.getValues()!="")
  {
    UIInstance.add(UIInstance.createLabel("_"));
    UIInstance.add(UIInstance.createHTML("<b>" + L1.getValues() + "</b>"));
  }
  if(L2.getValues()!="")
  {
    UIInstance.add(UIInstance.createLabel(' - - + ' + L2.getValues()));
  }
  if(L3.getValues()!="")
  {
    UIInstance.add(UIInstance.createHTML(" - - - - - + <a href=''www.google.co.uk''>" + L3.getValues() + "</a>",false));
  }
}
//add the sidebar
SpreadsheetApp.getUi()
  .showSidebar(UIInstance);

我想做的是,只要有人点击其中一个值(理想情况是L3值之一),它就会将该值插入当前单元格。不幸的是,我无法获得任何有效的东西(目前它只是在那里有一个谷歌链接,但即便没有出现)。

有没有人有任何想法?同样,必须动态创建侧边栏(已经是)。

1 个答案:

答案 0 :(得分:0)

使用单选按钮管理它。现在只有问题是获取参数。

//build the sidebar
  var UIInstance=UiApp.createApplication()
      .setTitle('Please choose Plant below:')
      .setWidth(250);
  //get the values over
  var MaxRow=250;
  var LookIn=0;
  var L1; var L2; var L3;
  for(LookIn=1;LookIn<MaxRow;LookIn++)
  {
    L1=sheet.getRange("AB" + LookIn);
    L2=sheet.getRange("AC" + LookIn);
    L3=sheet.getRange("AD" + LookIn);
    if(L1.getValues()!=""){UIInstance.add(UIInstance.createLabel("_")); UIInstance.add(UIInstance.createHTML("<b>" + L1.getValues() + "</b>"));}
    if(L2.getValues()!=""){UIInstance.add(UIInstance.createHTML("<b> > > " + L2.getValues() + "</b>"));}
    if(L3.getValues()!="")
    {
      var RadioHandler=UIInstance.createServerChangeHandler('radioButtonsChange');
      UIInstance.add(UIInstance.createRadioButton("MyButton").setId(L3.getValues).setText(L3.getValues()).addClickHandler(RadioHandler));
      UIInstance.add(UIInstance.createLabel(""));
    }
  }
  //add the sidebar
  SpreadsheetApp.getUi()
      .showSidebar(UIInstance);
}
相关问题