Google Sheets API v4 - 如何在具有值的最后一行之后插入行? [英] Google Sheets API v4 - How to insert row after the last row with value?

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

问题描述

我使用新的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表示法中有一些小技巧吗?

there some trick in the A1 Notation for this ?

我需要 .getLastRow Google Apps脚本

推荐答案

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.

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

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