Google Apps Script: how to make suggest box library to work?

后端 未结 1 1069
抹茶落季
抹茶落季 2021-01-27 12:06

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:

<         


        
相关标签:
1条回答
  • 2021-01-27 12:34

    small confusion here...

    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.

    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);
    }
    

    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.

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

    enter image description here

    0 讨论(0)
提交回复
热议问题