javascript - 在 Google App 脚本中返回多个参数值

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

我目前正在构建一个设置模式/侧边栏的工作表。我的问题是我确实需要从我的 *.gs 文件中的函数传递多个值。

目前我知道我可以实现这个:

google.script.run.withSuccessHandler(myFunction).gasFunction('argument value');

Index.html

<html>
<head></head>
<body>
<script>
    var hello = 'Not Working';
    google.script.run.withSuccessHandler(indexLog).logMe('hello');
    function indexLog(hello) {
        console.log(hello);
    }
</body>
</html>

气体脚本

function logMe(hello) {
    return  hello;
}

所以我处于多次运行连续方法以返回所需的所有参数的位置,即。

google.script.run.withSuccessHandler(indexLog).logMe('value 1');
google.script.run.withSuccessHandler(indexLog).logMe('value 2');
google.script.run.withSuccessHandler(indexLog).logMe('value 2');

我的值是单元格引用,但我需要一个范围而不是单个单元格值

然后我将获取这些值,并希望根据这些值构建一个数组,以便在我的 for 循环函数中正确地迭代这些值。

提前致谢!

最佳答案

这是方法的详细信息。

SpreadsheetApp.getActiveSheet().getRange(cell).getValue();

function returnCellValue(cell) {
    return (SpreadsheetApp.getActiveSheet().getRange(cell).getValue());
}

即使输入范围,也只会返回 1 个值。 getValue() 只返回 1 个值,无论范围如何。

SpreadsheetApp.getActiveSheet().getRange(cell).getValues();

function returnCellValue(cell) {
    return (SpreadsheetApp.getActiveSheet().getRange(cell).getValues());
}

使用 getValues() 将范围作为数组传递,然后我可以对其进行迭代。目前,Google App 脚本和表格仅支持触摸单元格的范围,因此如果它们不是引用单元格的相邻单元格,则您不能使用逗号分隔符来定义所需的所有范围。

关于javascript - 在 Google App 脚本中返回多个参数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35366006/

相关文章:

javascript - 从文本编辑器加载 html 时出现黑屏

javascript - Unix `ls` CSS3 命令样式

javascript - 如何以异步方式调用 10 个函数并收集所有结果并知道所有结果何时完成?

google-apps-script - 复制 Google 电子表格不再复制链接的表单

google-apps-script - 谷歌电子表格 : Set a default value to all the cells in a column with/with out script

google-apps-script - 比较两个电子表格并使用谷歌应用程序脚本输出差异

javascript - 为什么我可以设置任何事件类型字符串来调用 addEventListener 而没有 setTimeout 我会失去我的 css 效果?

regex - 在范围内使用时,带正则表达式的 Google Sheets 自定义函数在交替行上失败

google-sheets - 带条件查询或过滤最高值

google-sheets - Google 表格 - 基于上面单元格的相对条件格式