![](/img/trans.png)
[英]How to include a large external stylesheet and script in Google Apps Scripts Google Docs Extension
[英]Google Apps Script - template statements to include external files not working
我正在尝试使用外部 CSS 样式表。 然而,我得到的是 ' * include stylesheet * ' 在我的 html 侧栏中呈现。 我在 code.gs 文件中创建了包含函数。 为什么这不起作用?
索引.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<?!= include('stylesheet'); ?>
</head>
<body>
<script
src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
</body>
</html>
代码.gs
function onOpen() {
SpreadsheetApp.getUi()
.createMenu('Form')
.addItem('Open', 'openSidebar')
.addToUi();
}
function include(filename) {
return HtmlService.createHtmlOutputFromFile(filename)
.getContent();
}
function openSidebar(){
var htmlOutput = HtmlService.createHtmlOutputFromFile('Index');
htmlOutput.setTitle('Customer Inquiry Form');
SpreadsheetApp.getUi().showSidebar(htmlOutput);
}
样式表.html
<style>
body{
background-color:'gray';
}
</style>
在这个函数中:
function openSidebar(){
var htmlOutput = HtmlService.createHtmlOutputFromFile('Index');
htmlOutput.setTitle('Customer Inquiry Form');
SpreadsheetApp.getUi().showSidebar(htmlOutput);
}
您正在使用createHtmlOutputFromFile ,它将提供您的Index.html的内容,但它不会执行内部的脚本。
为了执行脚本,您需要创建一个HtmlTemplate然后调用evaluate()方法,您的函数应如下所示:
function openSidebar(){
var template = HtmlService.createTemplateFromFile('Index')
.evaluate()
.setTitle('Customer Inquiry Form')
SpreadsheetApp.getUi().showSidebar(template);
}
还要删除stylesheet.html 中值gray
的'
:
<style>
html{
background-color: gray;
}
</style>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.