![](/img/trans.png)
[英]HTML Dialog in Google Sheets google.script.run. fails to run Apps Script function
[英]Uncaught TypeError: google.script.run. is not a function
我有一个与Google电子表格相关联的代码,可通过脚本编辑器访问。 在代码中,我有一个.gs
文件作为主体,我有一个HTML文件,它是电子表格中使用的侧边栏。 我正在尝试从HTML编辑器中调用sheet.gs
文件中的函数,我是否会使用HTML文件中的“google.script.run.myFunction()”执行此操作,我这样做错了吗?
基本上在我的sheet.gs中我有
function myFunction() {
// do a thing
}
在我的HTML文件中,我试图像google.script.run.myFunction()
一样调用myFunction()
google.script.run.myFunction()
。
请帮我搞清楚,谢谢! 编辑:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~
我有这个功能,通过按钮点击调用
<div class="btn" onclick="generateSpreadsheetReport()">View Responses</div>
而且功能是
function generateSpreadsheetReport() {
console.log("RUN!");
console.log("StudentAverage1");
var day = document.getElementById("day");
if (!day.value) day.value = "";
var course = document.getElementById("courses");
var stud = document.getElementById("stud");
console.log(day.value,course.value,stud.value)
google.script.run.withSuccessHandler(displayAverage).sortByParameter(day.value||"", course.value||"", stud.value||"");
console.log("StudentAverage2");
google.script.run.getStudentAverage(); // <----- This line right here isn't working.
}
然后在我的sheet.gs中我有一个名为getStudentAverage()的函数,它被定义,当我从资源页面点击它时,它会显示在库中。 所以我假设我在HTML中称错了
看看下面的基本示例。 单击该按钮可触发电子表格中的Toast。 随意复制文档并检查代码
https://docs.google.com/spreadsheets/d/199k9x1Sn_NQJlNwB5JDZ_fgozEY0fFMYiXBiPHOQsR8/edit?usp=sharing
如果这不起作用,请分享更多代码。
不确定你的问题是什么,但从你的sheet.gs
的外观来看,尝试改变你的问题
myFunction() {
// do a thing
}
至
function myFunction() {
return true;
}
根据您解释的问题,这只是一个疯狂的猜测。 试试这个,让我们知道它是否适合你。
更新:从您的HTML文件调用myFunction()
类的
function myFunction() {
return true;
}
google.script.run.withSuccessHandler(function(myparam){
console.log("Response: "+myparam);
}).myFunction();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.