简体   繁体   English

Google表格通过根据匹配值附加列来添加注释

[英]Google Sheets add a note by appending column based on matching value

The goal is to add a note or several notes over time to a google sheet based on the value chosen.目标是根据选择的值随时间向谷歌表格添加一个或多个注释。

The script will allow for a button to be added in the sheet and run the script function to append to the next available column.该脚本将允许在工作表中添加一个按钮,并将脚本 function 到 append 运行到下一个可用列。

For example, the name Tim is chosen.例如,选择了姓名 Tim。 A note is written, the button is pressed to run the function and it will add it to Column D (since it is the next available column for Tim).写了一个注释,按下按钮运行 function 并将其添加到 D 列(因为它是 Tim 的下一个可用列)。

Another example, the name Jeff is chosen.另一个例子,选择了名字 Jeff。 A note is written.写了一个注释。 Since there are no more columns the append column should automatically create a new column and allow for the note to be written in "Jeff's" row, which would be Column G由于没有更多列 append 列应自动创建一个新列并允许将注释写入“Jeff's”行,即 G 列

Not sure if this is at all possible but hope to get some suggestions or ideas.不确定这是否可能,但希望得到一些建议或想法。

A一个 B C C D D E F F
Mark标记 B+乙+ completed assignment partly but needed extra time since..部分完成了任务,但需要额外的时间,因为.. 89433 89433 other其他
Tim蒂姆 A一个 checked检查
Jeff杰夫 C C n/a不适用 assignment # 4作业#4 done完毕 other其他
Steve史蒂夫 A一个 completed完全的 get file获取文件 received已收到
Elon伊隆 B-乙- three out of four四分之三 check email检查 email

Here's what I think you're trying to achieve -这就是我认为你想要实现的目标 -

添加注释

And, this code should help you get started -而且,此代码应该可以帮助您入门 -

function main() {
  const name = "Steve";
  const note = "HELLO"
  addNote(name, note);
}

function addNote(name, note) {
  const ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  const values = ss.getDataRange().getValues();
  for (var rowIndex = 0; rowIndex < values.length; rowIndex++) {
    let row = values[rowIndex];
    let nameColumn = row[0];
    if (nameColumn == name) {
      let rowValues = ss.getRange(`${rowIndex+1}:${rowIndex+1}`).getValues()[0]
      .filter(value => value !== "")
      let newColIndex = rowValues.length;
      ss.getRange(rowIndex+1, newColIndex+1).setValue(note);
    }
  }
}

Although, I'd highly recommend choosing something else as a unique identifier as opposed to a name because if there are 2 rows with the same name, then the code would actually add notes against both (incorrectly).虽然,我强烈建议选择其他东西作为唯一标识符而不是名称,因为如果有 2 行具有相同的名称,那么代码实际上会针对两者添加注释(错误地)。

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

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