Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script Google脚本:使用导入项目中的html文件_Google Apps Script_Web Applications - Fatal编程技术网

Google apps script Google脚本:使用导入项目中的html文件

Google apps script Google脚本:使用导入项目中的html文件,google-apps-script,web-applications,Google Apps Script,Web Applications,我想在一个通用的google脚本项目中保留公共资源,如css和js,然后将它们导入不同的项目(web应用程序) 因此,不要使用本地文件: <?!= HtmlService.createHtmlOutputFromFile('CSS').getContent(); ?> 我想使用导入文件中的资源(参考资料>库>导入项目)在库中,您需要共享HTML文件以及返回其内容的函数。然后可以在项目中调用这些函数 图书馆 代码G.gs: /** * Gets the CSS fil

我想在一个通用的google脚本项目中保留公共资源,如css和js,然后将它们导入不同的项目(web应用程序)

因此,不要使用本地文件:


    <?!= HtmlService.createHtmlOutputFromFile('CSS').getContent(); ?>


我想使用导入文件中的资源(参考资料>库>导入项目)

在库中,您需要共享HTML文件以及返回其内容的函数。然后可以在项目中调用这些函数

图书馆 代码G.gs:

/**
 * Gets the CSS file as HTML and returns its content.
 * @returns {string}
 */
function getCss() {
  return HtmlService.createHtmlOutputFromFile("CSS").getContent();
}
CSS.html

<style>
  p {
    background-color: yellow;
  }
</style>
Index.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <?!= Library.getCss(); ?>
  </head>
  <body>
    <p>Hello</p>
  </body>
</html>

你好

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <?!= Library.getCss(); ?>
  </head>
  <body>
    <p>Hello</p>
  </body>
</html>