如何使用Google App脚本获取Google电子表格最后一行的值 [英] How to get the value of last row of google spreadsheet using google app script

查看:79
本文介绍了如何使用Google App脚本获取Google电子表格最后一行的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用Google App脚本从Google电子表格的最后一行获取值或数据?我已经尝试了很多次,但是仍然无法获取数据.这样做的目的是获取记录的最后一个ID,以便我能够添加ID递增的另一条记录.

How i can get the value or data from the last row of the google spreadsheet using the google app script? I was tried many times all i can do, but still cant get the data. The purpose of this to the get the last ID of the record so that I able to add another record with ID incremented.

推荐答案

您可以使用getLastRow()获取包含内容的最后一行,如下所示:

You can use getLastRow() to get the last row that contains content, as shown here: https://developers.google.com/apps-script/reference/spreadsheet/sheet#getLastRow()

您应该可以从那里获取记录ID的值.我认为它看起来像这样,假设您的记录ID位于第1列:

From there you should be able to get the value of your record ID. I think it would look like this, assuming your record ID's are in column 1:

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

var lastRow = sheet.getLastRow();
Logger.log(lastRow); // Row index of last row to contain data
var myIDCol = 1;
var myID = sheet.getRange(lastRow, myIDCol).getValue();
Logger.log(myID); // Should be the value of your last record ID

这篇关于如何使用Google App脚本获取Google电子表格最后一行的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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