0

I'm working on a sidebar to display items from a one-column sheet titled "bib", and so far it has not been successful, even though I only modified the code where it's necessary, as I see it.

The code I followed is from: https://developers.google.com/apps-script/guides/html/templates

// from code.gs
function onOpen() {
  SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
      .createMenu('Custom Menu')
      .addItem('Show sidebar', 'showSidebar')
      .addToUi();
}

function showSidebar() {
  var html = HtmlService.createTemplateFromFile('Page') // updated code from createTemplateFromFile('Page')
  SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
      .showSidebar(html); // this line generates error with createTemplateFromFile
  html.data = SpreadsheetApp
      .getActive() // modified to getActive() because the sidebar is intended to be displayed while working on the active spreadsheet
      .getSheetByName('bib') // the sheet name where items are stored
      .getDataRange()
      .getValues();
  return html.evaluate();
}
// from Page.html
<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <table>
      <? for (var i = 0; i < data.length; i++) { ?>
        <tr>
          <? for (var j = 0; j < data[i].length; j++) { ?>
            <td><?= data[i][j] ?></td>
          <? } ?>
        </tr>
      <? } ?>
    </table>
  </body>
</html>

I expect a one-column table dynamically output the one-column sheet "bib", but instead I get

"Object does not allow properties to be added or changed."

Update: The suggested answer from some other question, createTemplateFromFile(filename), doesn't have sidebar as an argument. It leads to error:

"Invalid argument: userInterface"

mpa
  • 1
  • 2
  • 2
    Possible duplicate of [Adding a property to an Html template gives error "Object does not allow properties to be added or changed"](https://stackoverflow.com/questions/49725049/adding-a-property-to-an-html-template-gives-error-object-does-not-allow-propert) – tehhowch Jan 07 '19 at 13:44
  • My experience is a sidebar won't display from a simple onOpen trigger. Add it to the project installed trigger as an on open trigger and it should work. – TheWizEd Jan 07 '19 at 15:50
  • [Edit] to include your modified code or ask a new question. Voted to close this question as it's still a duplicate(sidebar shouldn't matter) – TheMaster Jan 07 '19 at 17:33
  • `showSidebar(`..`htmlOutput`..`)` only receives htmlOutput as the argument. `createTemplateFromFile` creates `HtmlTemplate`. You need to change them to `HtmlOutput` and then showSideBar. Flow: createTemplate> Modify template to include data > eval template to HtmlOutput > show output in sidebar. Read all methods available to HtmlTemplate in documentation. – TheMaster Jan 07 '19 at 17:50
  • Thank you for the tips on logic flow. – mpa Jan 07 '19 at 20:29

0 Answers0