Google Apps 脚本 - 包含外部文件的模板语句不起作用

问题描述 投票:0回答:1

我正在尝试使用外部 CSS 样式表。然而我得到的是 '* include stylesheet *' 在我的 html 侧边栏中渲染。我在 code.gs 文件中创建了 include 函数。为什么这不起作用?

索引.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);
}

stylesheet.html

<style>
 body{
  background-color:'gray';
 }
</style>
javascript html css google-apps-script
1个回答
3
投票

在此功能:

function openSidebar(){
 var htmlOutput = HtmlService.createHtmlOutputFromFile('Index');
 htmlOutput.setTitle('C
  background-color: gray;
 }
</style>
© www.soinside.com 2019 - 2024. All rights reserved.