谷歌Apps脚本:如何让提示框图书馆管理员的工作? [英] Google Apps Script: how to make suggest box library to work?

查看:169
本文介绍了谷歌Apps脚本:如何让提示框图书馆管理员的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试添加使用我的谷歌小号preadsheet自动完成功能<一个href=\"https://sites.google.com/site/scriptsexamples/learn-by-example/uiapp-examples-$c$c-snippets/suggest-box\"相对=nofollow>谷歌这Apps脚本提示框库从罗曼Vialard和詹姆斯·费雷拉的书:

I'm trying to add an autocomplete feature in my Google Spreadsheet using this Google Apps Script suggest box library from Romain Vialard and James Ferreira's book:

function doGet() {
  // Get a list of all my Contacts
  var contacts = ContactsApp.getContacts();
  var list = [];
  for(var i = 0; i < contacts.length; i++){
    var emails = contacts[i].getEmails();
    if(emails[0] != undefined){
      list.push(emails[0].getAddress());
    }
  }
  var app = UiApp.createApplication();
  var suggestBox = SuggestBoxCreator.createSuggestBox(app, 'contactPicker', 200, list);
  app.add(suggestBox);
  return app;
}


function onEdit() {
  var s = SpreadsheetApp.getActiveSheet();
  if( s.getName() == "my_sheet_name" ) { //checks that we're on the correct sheet
    var r = s.getActiveCell();
    if( r.getColumn() == 1) {
      doGet();
    }
  }
}

但是,当我开始编辑的my_sheet_name没什么hapens列1(如果我更换的doGet()其它功能,此功能等运行正常)。我已经安装了建议箱库。那么,为什么在的doGet()功能不起作用?

But when I start editing the column 1 of "my_sheet_name" nothing hapens (if I replace doGet() for other function, this other function runs Ok). I've already installed the Suggest Box library. So, why the doGet() function doesn't work?

推荐答案

下面的小混乱......

small confusion here...

的doGet()返回.....应用; 结构,它使用的是这里是需要进行部署,并与自己的网址在独立运行的webapps一个浏览器窗口。

The doGet() ..... return app; structure that you are using here is for standalone webapps that need to be deployed and run with their own url in a browser window.

你所要做的是在为preadsheet,其机制是不同的,显示的UI在一个弹出窗口:见下面的例子,有一个看的这里文档。

What you are trying to do is to show a Ui in a popup window in a spreadsheet, the mechanism is different : see example below and have a look at the documentation here.

function doGet_or_any_other_name_preferably_something_more_specific() {
  var contacts = ContactsApp.getContacts();
  var list = [];
  for(var i = 0; i < contacts.length; i++){
    var emails = contacts[i].getEmails();
    if(emails[0] != undefined){
      list.push(emails[0].getAddress());
    }
  }
  var app = UiApp.createApplication();
  var suggestBox = SuggestBoxCreator.createSuggestBox(app, 'contactPicker', 200, list);
  app.add(suggestBox);
  SpreadsheetApp.getActive().show(app);
}

请注意,这code将使UI展现出来,但仅此而已....没有数据将在S preadsheet写,因为你没有实现任何处理程序来处理数据返回。有关步骤的详细阅读上述文档和<一所示的例子href=\"https://sites.google.com/site/scriptsexamples/learn-by-example/uiapp-examples-$c$c-snippets/suggest-box\"相对=nofollow>罗曼的网站。

Note that this code will allow the Ui to show up but that's about all.... no data will be written in the spreadsheet since you didn't implement any handler to handle the data return. For details about that step read the aforementioned documentation and the examples shown on Romain's website.

修改您的评论如下:与此完全相同code测试(复制/粘贴)和工作,请参见下面捕获

EDIT following your comment : tested with this exact code (copied/pasted) and working, see capture below.

这篇关于谷歌Apps脚本:如何让提示框图书馆管理员的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆