javascript - 未捕获的 TypeError : google. script.run。不是函数

标签 javascript google-apps-script google-sheets google-apps

我有一个与 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/

相关文章:

for-loop - 替换列中的某些单元格值

google-apps-script - Google 脚本根据 2 列条件删除重复行

javascript - Google 表格、脚本在制作副本后停止工作。

javascript - JS定位加载后功能-添加延迟时间

c# - 从 Controller 控制我的 asp View 中的 javascript 代码是否将被执行

javascript - 用于检查表单的 Jquery UI 对话框

javascript - Google Apps 脚本 : Service invoked too many times for one day: email

javascript - 为什么 md-datepicker 不能在当前日期打开?

javascript - 我试图在大范围的特定单元格中挑选出所有带有 '1' 的行,是否有更有效的方法来做到这一点?

javascript - Google Apps 脚本中的数组支持哪些函数?