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

后端 未结 2 2033
囚心锁ツ
囚心锁ツ 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: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);
    }
    

提交回复
热议问题