简体   繁体   English

编写Google表格脚本,以仅在电子表格的一张表格中为每个新提交的表格提供具体的编号。

[英]Script google sheet to give a number specific on each new form submitted, only for one sheet of the spreadsheet.

First of all, thank you for all your participation, most of my answers are already replied in this stack overflow. 首先,感谢您的参与,我的大多数答案已经在堆栈溢出中得到了答复。

So, I would like to have, in a specific column, for each new form submitted, a specific number (like a tracking number for each form). 因此,我想在提交的每个新表格的特定列中有一个特定的编号(例如每个表格的跟踪编号)。

I did this code, which is working perfectly to do what i want : 我做了这段代码,可以完美地完成我想要的事情:

function onFormSubmit(e) {
var sheet = SpreadsheetApp.getActiveSheet();
var row =  SpreadsheetApp.getActiveSheet().getLastRow();
sheet.getRange(row,1).setValue(row+10071);
}

But my issue,that is working in all the sheet of my spreadsheet, and I want it only in a specific sheet. 但是我的问题在电子表格的所有工作表中都有效,我只希望在特定工作表中使用它。 So I tried with getSheetByName like this : 所以我尝试使用getSheetByName这样的:

 function onFormSubmit(e) {
var sheet = SpreadsheetApp.getSheetByName(mysheetname);
var mysheetname="Module2"
var row =  SpreadsheetApp.getSheetByName().getLastRow();
sheet.getRange(row,1).setValue(row+10071);
}

But is not working at all. 但是根本没有用。

Sorry for my bad english, but I did my best to be clear. 对不起,我的英语不好,但是我尽力了。 If someone can help me, I will be very grateful. 如果有人可以帮助我,我将非常感激。 Regards 问候

Paul 保罗

Perhaps try adding an IF to restrict the numbering to only that sheet: if (sheet.getName() = "*your sheet name*") 也许尝试添加一个IF以将编号限制为仅该工作表: if (sheet.getName() = "*your sheet name*")

So, all together it would be: 因此,总共将是:

function onFormSubmit(e) {
var sheet = SpreadsheetApp.getActiveSheet();
var row = SpreadsheetApp.getActiveSheet().getLastRow();
if (sheet.getName() = "*your sheet name*") {
  sheet.getRange(row,1).setValue(row+10071);
  }
}

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

相关问题 Google电子表格脚本。 仅适用于一张纸 - Google Spreadsheet Script. Only work for one sheet 将一行从一个Google表格电子表格复制到表单提交中的另一表格 - Copy a row from one Google Sheet Spreadsheet to Another on Form Submit 将工作表复制到另一个电子表格[Google Apps脚本] - Copy sheet to another spreadsheet [Google Apps Script] 仅生成电子表格的一张PDF - Generate PDF of only one sheet of my spreadsheet Google脚本每周在新工作表中复制和存档表单响应 - Google Script to copy and archive Form Responses in New Sheet on Weekly Basis 如何使用Google脚本在Google电子表格中除特定列以外的所有工作表大写? - How to capitalize all sheet except specific columns on Google spreadsheet using Google Script? 在我创建新工作表之前,Google Apps 脚本会复制工作表 - Google Apps Script copies a sheet before I create a new one Google电子表格脚本-仅授予对一张工作表的访问权限 - Google spreadsheets script - grant access to only one sheet Google表格脚本,用于将一个表格上的一些单元格值传递到新的表格行 - Google Sheets Script for passing a few cell values on one sheet to new sheet row 将一张工作表中的原始数据排序到Google App脚本中新工作表中的单独标签中 - Sorting raw data from one sheet into separate tabs on a new sheet in Google App Script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM