使用条件nodejs google工作表更新行中的特定值
我一直在尝试更新以相同名称,电子邮件等的现有行更新现有行。我的问题是我不知道如何在第二次试用WPM中为同一用户添加一个数字。
更明确的是,用户提交表单并在Web应用程序中启动操作,当第一个操作结束时,数据将发送到Google表格,用户将移动到第二个操作。我想将第二个操作的数据发送给用户使用相同名称,电子邮件。
app.post("/competition" , async (req, res) => {
const {Name, Email, Number, Faculty, University, first_Trial_WPM , first_Trial_CPM} = req.body;
const auth = new google.auth.GoogleAuth({
keyFile: "credentials.json",
scopes: "https://www.googleapis.com/auth/spreadsheets",
});
const client = await auth.getClient();
const googleSheets = google.sheets({version: "v4", auth: client});
const spreadsheetId = "###";
await googleSheets.spreadsheets.values.append({
auth,
spreadsheetId,
range: "Sheet1!A:G",
valueInputOption: "USER_ENTERED",
resource : {
values: [
[Name, Email, Number, Faculty, University, first_Trial_WPM , first_Trial_CPM]
]
}
})
res.render("competition2");
});
app.post("/home" , async (req, res) => {
const {Name, Email, Number, Faculty, University, second_Trial_WPM , second_Trial_CPM} = req.body;
const auth = new google.auth.GoogleAuth({
keyFile: "credentials.json",
scopes: "https://www.googleapis.com/auth/spreadsheets",
});
const client = await auth.getClient();
const googleSheets = google.sheets({version: "v4", auth: client});
const spreadsheetId = "###";
await googleSheets.spreadsheets.values.update({
auth,
spreadsheetId,
range: "Sheet1!A2:I1000",
valueInputOption: "USER_ENTERED",
resource : {
values: [
[Name, Email, Number, Faculty, University, second_Trial_WPM , second_Trial_CPM]
]
}
})
res.render('home');
});
I've been trying to update an existing row with the same name, email, etc.. my problem is that I can't figure out how to add a number in the second trial WPM for the same user.
to be more clear, the user submits a form and start the operation in the web app, when the first operation ends, the data is sent to google sheets and the user moves to the second operation. I want to send the data of the second operation to the user with the same name, email.
app.post("/competition" , async (req, res) => {
const {Name, Email, Number, Faculty, University, first_Trial_WPM , first_Trial_CPM} = req.body;
const auth = new google.auth.GoogleAuth({
keyFile: "credentials.json",
scopes: "https://www.googleapis.com/auth/spreadsheets",
});
const client = await auth.getClient();
const googleSheets = google.sheets({version: "v4", auth: client});
const spreadsheetId = "###";
await googleSheets.spreadsheets.values.append({
auth,
spreadsheetId,
range: "Sheet1!A:G",
valueInputOption: "USER_ENTERED",
resource : {
values: [
[Name, Email, Number, Faculty, University, first_Trial_WPM , first_Trial_CPM]
]
}
})
res.render("competition2");
});
app.post("/home" , async (req, res) => {
const {Name, Email, Number, Faculty, University, second_Trial_WPM , second_Trial_CPM} = req.body;
const auth = new google.auth.GoogleAuth({
keyFile: "credentials.json",
scopes: "https://www.googleapis.com/auth/spreadsheets",
});
const client = await auth.getClient();
const googleSheets = google.sheets({version: "v4", auth: client});
const spreadsheetId = "###";
await googleSheets.spreadsheets.values.update({
auth,
spreadsheetId,
range: "Sheet1!A2:I1000",
valueInputOption: "USER_ENTERED",
resource : {
values: [
[Name, Email, Number, Faculty, University, second_Trial_WPM , second_Trial_CPM]
]
}
})
res.render('home');
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信您的目标如下。
在这种情况下,以下修改如何?
修改后的脚本:
在此修改中,请修改您的第二个脚本,以将
second_trial_wpm的值放置为
和second_trial_cpm
如下所示。此修改后的脚本使用名称
和电子邮件
,second_trial_wpm
的变量,以及second_trial_cpm
。在此修改中,首先是从“ Sheet1”中检索的值。并且,使用
name
和电子邮件
的值检索行号以置于值。然后,second_trial_wpm
和second_trial_cpm
被放入搜索行的“ H”和“ I”列中。如果在“ Sheet1”的“ A”和“ B”列中检索了相同的名称,则将
second_trial_wpm的值
和second_trial_cpm
放在这些行上。 /p>参考:
I believe your goal is as follows.
In this case, how about the following modification?
Modified script:
In this modification, please modify your 2nd script for putting the values of
second_Trial_WPM
andsecond_Trial_CPM
as follows. This modified script uses the variables ofName
andEmail
,second_Trial_WPM
, andsecond_Trial_CPM
.In this modification, first, the values are retrieved from "Sheet1". And, retrieve the row numbers for putting values using the values of
Name
andEmail
. And then,second_Trial_WPM
andsecond_Trial_CPM
are put into the columns "H" and "I" of the searched row.If the same names are retrieved in columns "A" and "B" of "Sheet1", the values of
second_Trial_WPM
andsecond_Trial_CPM
are put to those rows.References: