我有一个与 Google 电子表格相关联的代码,可通过脚本编辑器访问。在代码中,我有一个 .gs
文件作为主体,我有一个 HTML 文件,它是电子表格中使用的边栏。我正在尝试调用 sheet.gs
中的函数来自 HTML 编辑器的文件,我是否会在 HTML 文件中使用“google.script.run.myFunction()”来执行此操作,我做错了吗?
基本上在我的 sheet.gs 我有
function myFunction() {
// do a thing
}
在我的 HTML 文件中,我试图调用
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
如果这不起作用,请分享更多代码。
关于javascript - 未捕获的 TypeError : google. script.run。不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44267866/