简体   繁体   中英

Returning Multiple Argument Values in Google App Script

I'm currently building a sheet which institutes a modal/sidebar. My issue is that I really need multiple values passed from a function in my *.gs file.

Currently I know I can implement this:

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>

GAS SCRIPT

function logMe(hello) {
    return  hello;
}

So I'm in a position where I'm running a continuous method multiple times in order to return all arguments needed, ie.

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

My values would be cell references, but I need a range not a single cell value

I'm then taking those values and would like to build an array from those to iterate the values across my for loop function correctly.

Thanks in advance!

It was in the minute details of the methods.

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

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

This will only return 1 value even if a range is inputted. getValue() only returns 1 value regardless of the range.

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

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

Using getValues() passed the range as an array that I could then iterate over. Currently Google App Scripts and Sheets only support ranges for touching cells so you cannot use a comma separator to define all ranges needed if they are not neighbors of the referenced cell.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM