在Google Spreadsheet API中查找最后写入的行 [英] Finding last written row in Google Spreadsheet API

查看:86
本文介绍了在Google Spreadsheet API中查找最后写入的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以找到您用Java在Google电子表格中写的最后一行吗?

Is there any way to find the last row you have written in a google spreadsheet in Java?

我试图通过在另一个文件中保留一个变量来做到这一点,并在每次进行另一次写作时都会对其进行更新.还有其他办法吗?

I tried to do that by having a variable which I keep in another file and I update that every time I do another writing. Is there any other way?

推荐答案

在Google Spreadsheet API中查找最后写入的行

我将首先使用REST调用为您提供一个概念,但是您必须在Java中应用它.

I'll give you a concept first using REST calls but you'll have to apply that in Java.

  1. 超出了您要写入的单元格的范围. 因此,要查找单元格A1:A10之间的最后写入的行,请使用范围A1:A11或A1:B(使用B表示将遍历单元格A中的所有行).
  2. 使用GET获取一系列单元格.解析响应结果.并获取解析值的长度. 该长度始终表示最后一行,因为Sheetsv4会忽略空白/空单元格.
  1. Exceed the range of cells where you're writing. So to find last written row between cells A1:A10, use the range A1:A11 or A1:B (using B means all the rows in cell A will be traversed).
  2. Fetch a range of cells, using GET. Parse the response result. And get the length of the parsed values. The length will always indicate the last row since Sheetsv4 ignores blank/empty cells.

因此,我有一个范围介于A1:A10之间的单元格.我在A10中写了你好".按照上面的概念,我可以这样做:

So example I have a range of cells between A1:A10. I wrote "hello" in A10. Following the concepts above I do this:

..
xhr.open('GET', 'https://sheets.googleapis.com/v4/spreadsheets/'+myspreadsheetId+'/values/Sheet1!A1:A10);
..
xhr.onload = function (oEvent) {
arrayBuffer = xhr.response; 
myArray = JSON.parse(arrayBuffer);
console.log("last row is " + myArray.values.length)
.. //output is 'last row is 10'

我的XHR请求的这一部分返回10.现在,我知道工作表中最后写入的行是A10.

This part of my XHR request returns 10. Now I know that the last written row in my sheet is A10.

要使用Java做到这一点,请使用基于此

还要检查有关使用Java编写数据单元的线程 .我认为它也提供了其他见解.

Also check this thread about writing on data cells using Java. I think it offers additional insight as well.

这篇关于在Google Spreadsheet API中查找最后写入的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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