Eli*_*ias 3 html javascript css google-sheets google-apps-script
我是Google Apps脚本的新手。我已经尝试了一些示例,这些示例都可以正常工作,但是我坚持使用CSS文件。
在我的code.gs中,我创建了include函数:
function include(filename) {
return HtmlService.createHtmlOutputFromFile(filename)
.getContent();
}
Run Code Online (Sandbox Code Playgroud)
我还创建了css文件“ Sidebar.css.html”,其中包含一些样式参数:
<style>
.branding-below {
bottom: 56px;
top: 0;
}
.branding-text {
left: 7px;
position: relative;
top: 3px;
}
.col-contain {
overflow: hidden;
}
.col-one {
float: left;
width: 50%;
}
.logo {
vertical-align: middle;
}
.radio-spacer {
height: 20px;
}
.width-100 {
width: 100%;
}
</style>
Run Code Online (Sandbox Code Playgroud)
在我的Sidebar.html中,我尝试包含CSS:
<?!= include('Sidebar.css.html'); ?>
Run Code Online (Sandbox Code Playgroud)
这显然没有用。结果如下:
在此链接中您可以看到结果(抱歉,我没有足够的人来张贴它):http : //dl1.joxi.net/drive/0005/1191/378023/150727/371cdf01c0.jpg
我该怎么办?
createHtmlOutputFromFile
您将要使用createTemplateFromFile
和evaluate
模板,而不是使用。您添加侧边栏的代码应如下所示:
function showSidebar() {
var template = HtmlService.createTemplateFromFile('Sidebar');
var ui = template.evaluate().setTitle('Translate');
SpreadsheetApp.getUi().showSidebar(ui);
}
Run Code Online (Sandbox Code Playgroud)