Google Apps Script - HTML service “createTemplateFromFile” not usable from within App (spreadsheet, etc.)?

后端 未结 2 2007
囚心锁ツ
囚心锁ツ 2021-01-12 14:45

The docs for HtmlService don\'t state that this shouldn\'t work, but it seems that the template approach is limited to web app Apps Script projects.

I am attempting

相关标签:
2条回答
  • 2021-01-12 15:23

    It seems you haven't gone through the documentation in detail. Please, look at the reference documentation of class HtmlTemplate.

    0 讨论(0)
  • 2021-01-12 15:28

    You need to evaluate() a template to create an HtmlOutput object.

    function showSidebar(){
    
      var html = HtmlService.createTemplateFromFile('changeDialog');
    
      var a = "test";
    
        SpreadsheetApp.getUi() 
          .showSidebar(html.evaluate());
                            //////////
    }
    

    Since your changeDialog.html file contains no template tags, you could instead create an HTML file from it directly:

    function showSidebar(){
    
      var html = HtmlService.createOutputFromFile('changeDialog');
                                   //////
    
      var a = "test";
    
        SpreadsheetApp.getUi() 
          .showSidebar(html);
    }
    
    0 讨论(0)
提交回复
热议问题