Google表格API追加方法(最后排在最前面) [英] Google sheets API append method (last on top)

查看:75
本文介绍了Google表格API追加方法(最后排在最前面)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用谷歌表格api追加方法(任何语言)时,要追加到表格的值会添加到最后一个非null行之后. 因此,新值将出现在工作表的底部,如下所示: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/append#InsertDataOption

When using google sheets api append method (in any language), the values to be appended to the sheet are added after the last non null row. So new values appear at the bottom of the sheet, as explained here: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/append#InsertDataOption

如何以新值出现在工作表顶部的方式附加值?

How can I append values in a way that the new values appear at the top of the sheet?

推荐答案

您要通过插入新行来附加值.如果我的理解是正确的,那么这种方法呢?似乎sheets.spreadsheets.values.append将值附加到最后一行.因此,我建议使用sheets.spreadsheets.batchUpdate.端点和请求主体如下.使用此功能时,请修改### spreadsheet ID ###"sheetId": 1234567890以及范围和值的参数.

You want to append values by inserting new rows. If my understanding is correct, how about this method? It seems that sheets.spreadsheets.values.append appends values to the last row. So I would like to propose to usesheets.spreadsheets.batchUpdate. The endpoint and request body are as follows. When you use this, please modify ### spreadsheet ID ###, "sheetId": 1234567890 and the parameters for range and values.

POST https://sheets.googleapis.com/v4/spreadsheets/### spreadsheet ID ###:batchUpdate

请求正文:

{
 "requests": [
  {
   "insertRange": {
    "range": {
     "sheetId": 1234567890,
     "startRowIndex": 0,
     "endRowIndex": 1
    },
    "shiftDimension": "ROWS"
   }
  },
  {
   "pasteData": {
    "data": "sample1, sample2, sample3",
    "type": "PASTE_NORMAL",
    "delimiter": ",",
    "coordinate": {
     "sheetId": 1234567890,
     "rowIndex": 0,
    }
   }
  }
 ]
}

此请求的流程:

  1. 使用"insertRange"将新行插入第1行.
  2. 使用"pasteData"导入"sample1,sample2,sample3"的值.

更改"insertRange"和"pasteData"的顺序时,首先,将覆盖"A1:A3"的值.之后,将新行插入到行1.因此,似乎是数组的"requests"元素按顺序运行.

When the order of "insertRange" and "pasteData" is changed, at first, the value of "A1:A3" is overwritten. After this, the new row is inserted to the row 1. So it seems that the elements of "requests" which is an array run in the order.

如果我误解了你的问题,对不起.

If I misunderstand your question, I'm sorry.

这篇关于Google表格API追加方法(最后排在最前面)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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