如何在具有值的最后一行之后插入行

如何在具有值的最后一行之后插入行

本文介绍了如何在具有值的最后一行之后插入行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用新的Google Sheets API v4将数据插入电子表格中,代码可以完美工作,并且数据可以很好地插入到工作表中.

I am inserting data into a spreadsheet with the new Google Sheets API v4, the code works perfect and the data it is inserted well in the sheet.

但是如何找出包含数据的最后一行以在此之后添加数据呢?

But how to find out the last row with data to add the data after this ?

List<List<Object>> arrData = getData();

ValueRange oRange = new ValueRange();
oRange.setRange("Pedidos!AXXXXXXX"); // I NEED THE NUMBER OF THE LAST ROW
oRange.setValues(arrData);

List<ValueRange> oList = new ArrayList<>();
oList.add(oRange);

BatchUpdateValuesRequest oRequest = new BatchUpdateValuesRequest();
oRequest.setValueInputOption("RAW");
oRequest.setData(oList);

BatchUpdateValuesResponse oResp1 = mService.spreadsheets().values().batchUpdate("ID_SPREADSHEET", oRequest).execute();

在A1表示法中是否有此技巧?

Is there some trick in the A1 notation for this?

我需要与Google Apps脚本中的.getLastRow等效.

I need an equivalent to .getLastRow from Google Apps Script.

推荐答案

v4 API无法询问数据的最后一行是什么",因为它是与Apps Script API不同的API样式.您可以通过请求数据并计算从第一个请求的行到最后返回的行的偏移​​量来推断最后一行.

The v4 API has no way to ask "what is the last row with data", as it's a different style of API than the Apps Script API. You can infer the last row yourself by requesting the data and counting the offset from your first requested row to the last returned row.

这篇关于如何在具有值的最后一行之后插入行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 18:54