Google Sheets API-如何在表格的顶部附加新行?(Android) [英] Google Sheets API- How do I append new rows on TOP of table?(Android)

查看:128
本文介绍了Google Sheets API-如何在表格的顶部附加新行?(Android)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Android应用中,我想在Google表格的顶部添加一行(包含新的食品订单信息).从 https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/append 文档,听起来我只能追加到表格底部.但是我确实需要从TOP追加新行,并且我怀疑那是不可能的.
我可以使用以下代码将行追加到底部:

In my Android App, I would like to append a row (with new food order information) to the top of a google sheets table. From the https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/append documentation it sounds like I'm only able to append to the bottom of a table. But I realy need to append the new row from TOP, and I doubt that's impossible.
I was able to append rows to the bottom, using this code:

String ORDER_SHEET_ID = "<my speardsheet id here>";
String ORDERS_RANGE_DINING = "DiningOrders!C5:I";
//...                       
this.mService.spreadsheets().values().append(ORDER_SHEET_ID,ORDERS_RANGE_DINING, body)
.setValueInputOption("RAW").setInsertDataOption("INSERT_ROWS").execute();

是否可以将行追加到表格顶部?如何?谢谢!

Is it possible to append the row to the top of the table? How? Thanks!

推荐答案

这是我用来插入新行的方法.它创建该行并使用paste命令设置数据,因此我可以一次HTTP往返执行所有操作.或者,您可以根据需要使用第二个请求来更新数据.我不确定粘贴"命令是否可以插入行,但是可以.

This is what I use to insert a new row. It creates the row and uses the paste command to set the data so I can do everything in one HTTP round trip. Alternatively you could update the data using a second request if you want. I'm not sure if the Paste command can insert rows or not, but this works.

InsertDimensionRequest insertRow = new InsertDimensionRequest();
insertRow.setRange(new DimensionRange().setDimension("ROWS").setStartIndex(0).setEndIndex(1).setSheetId(sheetId));
PasteDataRequest data = new PasteDataRequest().setData("Data").setDelimiter("\t")
        .setCoordinate(new GridCoordinate().setColumnIndex(0).setRowIndex(0).setSheetId(sheetId));

BatchUpdateSpreadsheetRequest r = new BatchUpdateSpreadsheetRequest().setRequests(Arrays.asList(
        new Request().setInsertDimension(insertRow),
        new Request().setPasteData(data)
        ));
BatchUpdateSpreadsheetResponse response = this.mService.spreadsheets().batchUpdate(SHEET_ID, r).execute();

这篇关于Google Sheets API-如何在表格的顶部附加新行?(Android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆