使用包含时应用程序脚本边栏参考错误(Apps Script Sidebar Reference Error When Using Include)

编程入门 行业动态 更新时间:2024-10-24 22:19:45
使用包含时应用程序脚本边栏参考错误(Apps Script Sidebar Reference Error When Using Include)

我创建了一个Google Apps Script插件,在点击时显示一个侧边栏:

function displayPage_() { getScriptProperties_() var htmlTemplate = HtmlService.createTemplateFromFile('PAGE'); var html = htmlTemplate.evaluate() .setTitle('Connector'); SpreadsheetApp.getUi().showSidebar(html); }

只要它是简单的html,就可以成功加载文件PAGE.html 。 但是,当我尝试添加这样的include :

<!DOCTYPE html> <html> <head> <base target="_top"> <?!= include("STYLESHEET"); ?> </head> <body> </body> </html>

它会抛出这个错误:

[17-02-09 08:55:50:239 MST] Execution failed: ReferenceError: "include" is not defined.

不管include什么,它总是失败。

我之前完成了这个工作,它工作。 据我所知,我的设置与其他项目一样,但在此项目中不起作用。 我假设我忘记启用某些内容,但不知道如何判断缺失的内容,因为记录内容很模糊。

我错过了什么? 或者,做错了?

I created a Google Apps Script add-on to display a sidebar on click:

function displayPage_() { getScriptProperties_() var htmlTemplate = HtmlService.createTemplateFromFile('PAGE'); var html = htmlTemplate.evaluate() .setTitle('Connector'); SpreadsheetApp.getUi().showSidebar(html); }

This successfully loads the file PAGE.html as long as it is simple html. However, when I try to add include like this:

<!DOCTYPE html> <html> <head> <base target="_top"> <?!= include("STYLESHEET"); ?> </head> <body> </body> </html>

It throws this error:

[17-02-09 08:55:50:239 MST] Execution failed: ReferenceError: "include" is not defined.

It doesn't matter what is in the include it always fails.

I have done this before and it worked. As far as I can tell, I have this set up just like the other project, but it doesn't work in this project. I assume that I forgot to enable something, but don't know how to tell what is missing because the transcript is vague.

What am I missing? Or, doing wrong?

最满意答案

我也疯了......在Google脚本参考中提供的示例中找到它,我不知道的是include()是用户定义的函数。 粘贴这个代码,它会工作:

function include(File) { return HtmlService.createHtmlOutputFromFile(File).getContent(); };

如果我理解正确,请告诉我。

I got crazy too... Found it in an example provided in Google Script Reference, what I didn't know was that include() is a user-defined function. Paste this code and it will work:

function include(File) { return HtmlService.createHtmlOutputFromFile(File).getContent(); };

Let me know if I understood properly.

更多推荐

本文发布于:2023-08-06 15:51:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1451540.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时应   脚本   错误   程序   Apps

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!