我有一个与谷歌电子表格相关的代码,可以通过脚本编辑器访问。在代码中,我有一个 .gs 文件作为主体和一个 HTML 文件作为电子表格中使用的侧边栏。我试图从 HTML 编辑器中调用 sheet.gs 文件中的函数,我应该在 HTML 文件中使用 google.script.run.myFunction() 来完成这个操作吗?我做错了吗?
基本上,在我的 sheet.gs 文件中,我有:
基本上,在我的 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 中调用它的方式不正确。
sortByParameter()
,将google.script.run.getStudentAverage();
更改为google.script.run.withSuccessHandler().getStudentAverage();
。请参阅文档 - Class google.script.run (Client-side API) 以获取代码实现和指南。希望这能有所帮助。 - Mr.Rebot