【发布时间】:2021-07-15 17:08:18
【问题描述】:
在侧边栏上,谷歌应用脚本htmlservice.createTemplateFromFile(file) 用于根据用户请求启动侧边栏。
当htmlfile(客户端html文件)位于根文件夹时,一切顺利。
我想将项目文件重新排列到几个子文件夹中。
我正在使用 visual studio code 和 clasp 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 如果我以前没有看到这个,我正在失去我的创造力。如果你会回答,我会把它标记为答案