简体   繁体   English

Google-apps-script:简单支票值-返回值

[英]Google-apps-script: Simple Check Value - Return Value

I have a Google Sheet accepting form responses, and I want to have a value placed in the first blank cell in the row when a response arrives. 我有一个接受表格回复的Google表格,并且希望在回复到达时在行的第一个空白单元格中放置一个值。

For example, when this script sees a response arrive from the form in row 15, and if the last value from the form fills cell D15, it should place an "X" in cell E15. 例如,当此脚本看到第15行中的表单有响应时,如果表单的最后一个值填充了单元格D15,则应在单元格E15中放置一个“ X”。

I have built apps with php, but am a javascript newb. 我已经用php构建了应用程序,但它是JavaScript newb。 Can anyone point me in the right direction for ideas of how to approach this in Google Sheets/Scripts? 谁能为我指出正确的方向,以提供有关如何在Google表格/脚本中实现此目标的想法?

Here is what I have so far: 这是我到目前为止的内容:

function ?(event) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();

//if form is submitted
if (event.?values[?] == '?') {
//Add "X" to the first empty cell in the row
?.?("x");
}
}

I have added "?"s where I am stuck. 我在卡住的地方添加了“?”。 Many thanks in advance for any help! 在此先感谢您的帮助!

I would make use of the triggers for form submission within Google Sheets: 我会利用Google表格中的表单提交触发器

function onEdit(e){
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var range = e.range; // Get the cells in the spreadsheet that were edited
  var col = range.getLastColumn(); // Last column with data
  var row = range.getRow(); // Row containing the new data
  sheet.getRange(row,col+1).setValue('X')
}

The above code should find the new row in the form response sheet, find the last column of existing data, and add the 'X' to the first unoccupied column. 上面的代码应在表单响应表中找到新行,找到现有数据的最后一列,并将“ X”添加到第一列未占用的列。 Let me know if this works for you! 让我知道这是否适合您!

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

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