【问题标题】:Returning Multiple Argument Values in Google App Script在 Google App 脚本中返回多个参数值
【发布时间】:2016-02-12 15:15:24
【问题描述】:

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

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

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

索引.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 循环函数中正确地迭代这些值。

提前致谢!

【问题讨论】:

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


    【解决方案1】:

    这是方法的细节。

    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 脚本和表格仅支持触摸单元格的范围,因此如果它们不是所引用单元格的邻居,则不能使用逗号分隔符来定义所需的所有范围。

    【讨论】:

      猜你喜欢
      • 2016-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-15
      • 1970-01-01
      • 1970-01-01
      • 2020-10-31
      相关资源
      最近更新 更多