简体   繁体   English

Google App脚本>电子表格>获取行ID?

[英]Google App Script > Spreadsheet > get row id?

Besides the row index, which you can get using Range.getRowIndex() , is there any unique identifier for a row in a spreadsheet? 除了可以使用Range.getRowIndex()获得的行索引外,电子表格中的行是否还有唯一标识符? If yes, what's the API for this? 如果是,此的API是什么? I don't see it in the Google docs. 我没有在Google文档中看到它。

I'm weary to lean on the row index because a user might swap or delete rows manually, and there goes comparisons... 我厌倦了依靠行索引,因为用户可能会手动交换或删除行,并且进行比较...

I want to be able to uniquely identify a form submission. 我希望能够唯一地标识表单提交。

There's a unique form response id that you can set in the row... 您可以在该行中设置一个唯一的表单响应ID。

e.response.getId(); e.response.getId();

Where 'e' is the object being passed to your form submit function. 其中“ e”是传递给表单提交功能的对象。

Sorry for answering such an old query, but the Googles turned it up as an answer to my own question (how are form responses and spreadsheet rows related). 很抱歉回答这样一个旧查询,但Google却把它作为对我自己的问题(表单响应和电子表格行之间的关系)的回答。

Given the form ID, it's possible to use the Google Apps Script Forms Service to get all of the responses, and for each one to get it's ID and timestamp, and use the Spreadsheet Service to store the ID in the row with matching timestamp: 给定表单ID,可以使用Google Apps脚本表单服务获取所有响应,并为每个响应获取ID和时间戳,并使用电子表格服务将ID存储在具有匹配时间戳的行中:

var form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz');
var responses = form.getResponses();
for (var i = 0; i < responses.length; i++) {
    var response = responses[i];
    Logger.log(response.getId());
    Logger.log(response.getTimestamp());
    // use Spreadsheet API to get matching row and store ID
}

https://developers.google.com/apps-script/reference/forms/ https://developers.google.com/apps-script/reference/forms/

https://developers.google.com/apps-script/reference/spreadsheet/ https://developers.google.com/apps-script/reference/spreadsheet/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM