如何从另一个库引用Google Apps脚本.html文件? [英] How can I reference a Google Apps Script .html file from another library?

查看:66
本文介绍了如何从另一个库引用Google Apps脚本.html文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一组HTML页面,这些页面将在Google表格侧边栏中提供,并将连接到我们的内部数据库.每个页面都在单个Google Apps脚本项目中以自己的.html文件设置.

I'm writing a set of HTML pages that will be served on the Google Sheets sidebars and will connect to our internal database. Each page is set up on its own .html file within a single Google Apps Script project.

我想将这些文件提取到一个项目中,并像使用其他.gs脚本文件一样将其作为库引用.具体来说,如何在下面编写"MyLib.page"行?

I'd like to pull these files out to a single project and reference this as a library like I can do with my other .gs script files. Specifically, how can I write the "MyLib.page" line below?

图书馆项目:

Code.gs

function myFunc() { Logger.log("Hallo Werld!");}

page.html

<h1>
  Hello world!
</h1>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
  $(document).ready(function() {
     google.script.run.myFunc();
     });
</script>

电子表格脚本编辑器(包含的库标识符:MyLib)

Code.gs

function callLibFunc() {
  MyLib.myFunc();
}

function loadSidebar() {
  var html = HtmlService.createTemplateFromFile("MyLib.page").evaluate()
             .setSandboxMode(HtmlService.SandboxMode.IFRAME);
  SpreadsheetApp.getUi().showSidebar(html);
}

推荐答案

使Lib打开侧边栏:

图书馆项目:

Code.gs

function loadSidebar() {
  var html = HtmlService.createTemplateFromFile("MyLib.page").evaluate()
             .setSandboxMode(HtmlService.SandboxMode.IFRAME);
  SpreadsheetApp.getUi().showSidebar(html);
}

电子表格脚本编辑器

Code.gs

function callLibFunc() {
  MyLib.loadSidebar();
}

这篇关于如何从另一个库引用Google Apps脚本.html文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆