Google Sheets API v4 - How to get the last row with value?

前端 未结 4 1860
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-10 03:27

How to get the last row with value in the new Google Sheets API v4 ?

i use this to get a range from a sheet:

mService.spreadsheets().values().get(\"I         


        
4条回答
  •  猫巷女王i
    2020-12-10 04:26

    You don't need to. Set a huge range (for example A2:D5000) to guarantee that all your rows will be located in it. I don't know if it has some further impact, may be increased memory consumption or something, but for now it's OK.

    private List getDataFromApi() throws IOException {
            String spreadsheetId = "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms"; 
            String range = "A2:D5000";
            List results = new ArrayList();
            ValueRange response = this.mService.spreadsheets().values()
                    .get(spreadsheetId, range)
                    .execute();
            List> values = response.getValues();
            if (values != null) {
                results.add("Name, Major");
                for (List row : values) {
                    results.add(row.get(0) + ", " + row.get(3));
                }
            }
            return results;
        }
    

    Look at the loop for (List row : values). If you have two rows in your table you will get two elements in values list.

提交回复
热议问题