在v3 API中,我可以执行以下操作:
String listFeedUrl = (new URI(worksheet.getListFeedUrl().toString())).toURL();
ListQuery lq = new ListQuery(listFeedUrl);
lq.setOrderBy("column:name");
lq.setReverse(false);
ListFeed lf = spreadsheetService.query(lq, ListFeed.class);
在第4节中,我没有看到相同的内容。获取已排序单元格数据的推荐方法是什么?一旦它被退回,我是唯一的选择吗?
答案 0 :(得分:2)
实际上你可以做到这一点,但我们的想法是在工作表上执行一个请求来明确地对列进行排序。我设法这样做了:
BatchUpdateSpreadsheetRequest busReq = new BatchUpdateSpreadsheetRequest();
SortSpec ss = new SortSpec();
// ordering ASCENDING or DESCENDING
ss.setSortOrder("DESCENDING");
// the column number starting from 0
ss.setDimensionIndex(1);
SortRangeRequest srr = new SortRangeRequest();
srr.setSortSpecs(Arrays.asList(ss));
Request req = new Request();
req.setSortRange(srr);
busReq.setRequests(Arrays.asList(req));
// mService is a instance of com.google.api.services.sheets.v4.Sheets
this.mService.spreadsheets().batchUpdate(spreadsheetId, busReq).execute();
答案 1 :(得分:1)
似乎答案是否。见here
Order by column is not supported for reads, but it is possible to sort the data in the sheet (using a SortRange) request and then read it