Java | How to find a value (row and column number) in range of google spreadsheet using API?

后端 未结 2 607
眼角桃花
眼角桃花 2021-01-26 08:53

I am using the Java API (V4) to read and edit the data from a google sheet. So far, I am able to read and edit the data based on the row and column number (index).

相关标签:
2条回答
  • 2021-01-26 09:36

    Find text is not yet available for Google Sheet API. Please star this issue tracker FR to get notified on any updates.

    A workaround based on this SO answer, "You can get the data for the range you are searching on, and then iterate over it looking for a match. " Here is his code snippet:

    /**
    * Finds a value within a given range. 
    * @param value The value to find.
    * @param range The range to search in.
    * @return A range pointing to the first cell containing the value, 
    * or null if not found.
    */
    function find(value, range) {
    var data = range.getValues();
    for (var i = 0; i < data.length; i++) {
    for (var j = 0; j < data[i].length; j++) {
    if (data[i][j] == value) {
    return range.getCell(i + 1, j + 1);
    }
    }
    }
    return null;
    }
    

    NOTE: Code sample is in google-apps-script

    Like in this code snippet, you will need to set the range first, then check if value will match inside the range.

    0 讨论(0)
  • 2021-01-26 09:52

    According to the documentation, you can find the value using : FindReplaceRequest() and .getFind();

    String cellReq = (new FindReplaceRequest().setFind("samuel")).getFind();
    
    0 讨论(0)
提交回复
热议问题