【问题标题】:call google app script htmlservice.createTemplateFromFile(file) with file located on sub folder使用位于子文件夹中的文件调用谷歌应用脚​​本 htmlservice.createTemplateFromFile(file)
【发布时间】:2021-07-15 17:08:18
【问题描述】:

在侧边栏上,谷歌应用脚​​本htmlservice.createTemplateFromFile(file) 用于根据用户请求启动侧边栏。

当htmlfile(客户端html文件)位于根文件夹时,一切顺利。

我想将项目文件重新排列到几个子文件夹中。 我正在使用 visual studio codeclasp push 将更改推送到服务器。

一切都很好,除了file 位置。 在移动file 时,我找不到提供正确路径的方法。

例如: 在重新排列两个文件(和其他文件)之前在谷歌编辑器上。

  • client.html
  • server.gs

在移动到子文件夹并推送到服务器后,由于编辑器不支持子文件夹,它会反映在文件名中:

  • ./subFolder/client.html
  • ./subFolder/sever.gs

我还将服务器 js(谷歌编辑器中的 gs)移动到同一个文件夹

服务器中用于启动侧边栏的代码

function launchSideBar(){    
    //try obvious
    let file = "client"; // #1
    file = "./client"; // #2
    
    //like it displays in editor
    file = ".subFolder/client"; // #3
    
    /*maybe server is launched from root, 
      although it also resides on sun folder, so supply 
      relative path from root, like for other files (css,ims etc)
    */
    file = "./subFolder/client"; // #4

    let output = 
        HtmlService.createHtmlOutputFromFile(file);

    //launch
    SpreadsheetApp.getUi() 
      .showSidebar(output);
    
} 

你可以看到我尝试过的 4 个选项(当然每次只有一个不同的选项没有评论)

当试图从工作表添加的菜单项中显示侧边栏时,出现错误消息

Exception: No HTML file named subFolder/client was found.  

当然每次文件名都不一样。

服务器被自动识别,虽然也被移动了。

想法?

【问题讨论】:

  • 改用subFolder/client
  • @TheAddonDepot 如果我以前没有看到这个,我正在失去我的创造力。如果你会回答,我会把它标记为答案

标签: google-apps-script


【解决方案1】:

尝试改用file = "subFolder/client"

【讨论】:

    猜你喜欢
    • 2015-01-20
    • 1970-01-01
    • 1970-01-01
    • 2016-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多