Retrieve rows from spreadsheet data using google app script

后端 未结 2 1471
有刺的猬
有刺的猬 2020-12-23 18:55

I am using Google app script to write form data to spreadsheet. Now I would like to fetch the values from Excel which matches conditions (eg., filtered by date, username) an

相关标签:
2条回答
  • 2020-12-23 19:08

    The easiest way, and the one I know, is to :
    get the values in an Array using

    var data = SpreadsheetApp.getActiveSheet().getDataRange().getValues();
    

    then to make a loop

    for (i in data) {
    

    in this loop to check if the date (data[i][0]) is equal to the one you're looking for, and if the name (data[i][1]) is equal to the one you're looking for too. And push it to an array

    var labels=new Array;
    label.push( [data[i][0], data[i][1], data[i][2]] );
    

    then having all your data in this array, you can populate a panen Ui with label using a for loop

    for (i in labels) { ...
    
    0 讨论(0)
  • 2020-12-23 19:18

    Well, you can consider use a cell and use the "Query" formula on it. Lets assume Date is at Column A, Username = Column B, Comment is Column C, while the blank cell is D1, your script will look like this:

    SpreadsheetApp.getActiveSheet().getRange("D1").setFormula('Query(A:C,"SELECT A,B,C WHERE B="' + "SomeOne'" + ',1)'; //filter the data and populate to D1 onwards    
    SpreadsheetApp.getActiveSheet().getRange("D:F").getValues();//this is the filtered data
    
    0 讨论(0)
提交回复
热议问题