[英]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 ![]() |
D ![]() |
E![]() |
F ![]() |
---|---|---|---|---|---|
Mark![]() |
B+![]() |
completed assignment partly but needed extra time since..![]() |
89433 ![]() |
other![]() |
|
Tim![]() |
A![]() |
checked![]() |
|||
Jeff![]() |
C ![]() |
n/a![]() |
assignment # 4![]() |
done![]() |
other![]() |
Steve![]() |
A![]() |
completed![]() |
get file![]() |
received![]() |
|
Elon![]() |
B-![]() |
three out of four![]() |
check 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.