使用包括时的Apps脚本边栏参考错误

编程入门 行业动态 更新时间:2024-10-21 04:18:16
本文介绍了使用包括时的Apps脚本边栏参考错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我创建了一个Google Apps Script加载项以在单击时显示侧边栏:

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); }

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

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>

它抛出此错误:

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

include中的什么都不重要,它总是会失败.

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()是用户定义的函数.粘贴此代码即可使用:

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.

更多推荐

使用包括时的Apps脚本边栏参考错误

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

发布评论

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

>www.elefans.com

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