我目前正在构建一个设置模式/侧边栏的工作表。我的问题是我确实需要从我的 *.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/