[英]Writing data to a cell in Google Sheets from a 3rd party link
How do I make a link that adds data to a Google Sheet?如何创建将数据添加到 Google 表格的链接?
I am working on a student calling system that allows the following: 1-Parents arrive at our school's entrance and show a QR Code 2-The QR Code is a link that specifies their child's name, year, etc. 3-That data is then sent to a Google Sheet that is being displayed in our assembly hall so the student knows their parent has arrived我正在开发一个学生呼叫系统,该系统允许以下操作: 1-家长到达我们学校的入口处并出示二维码 2-二维码是一个链接,其中指定了他们孩子的姓名、年份等。 3-然后是该数据发送到在我们礼堂展示的谷歌表格,以便学生知道他们的父母已经到达
It seems like this should work, but I'm missing something: Allowing for third party updates to Google Spreadsheets via email response?看起来这应该可行,但我错过了一些东西: 允许第三方通过 email 响应更新 Google 电子表格?
I understand (and can do) how to write a Script and publish as a WebApp, and even to add parameters to that WebApp that are passed as variables, but how do I choose which Google Sheet document to add the data to?我了解(并且可以做到)如何编写脚本并作为 WebApp 发布,甚至可以将参数添加到作为变量传递的 WebApp,但是如何选择将数据添加到哪个 Google Sheet 文档?
Since this is still conceptual, I don't have any examples, but would greatly appreciate some guidance.由于这仍然是概念性的,我没有任何示例,但非常感谢一些指导。 I have a decent understanding of coding/scripts, but I'm no expert.我对编码/脚本有很好的理解,但我不是专家。
I have figured it out.我已经想通了。 I was trying to write the Google Sheet WebApp in a seperate document, but I have now added it to the same document.我试图在单独的文档中编写 Google Sheet WebApp,但我现在已将其添加到同一个文档中。 Here is what I did:这是我所做的:
In a Google Sheet - Go to Extensions - Apps Scripts在 Google 表格中 - Go 到扩展 - 应用程序脚本
Use the following code in Code.gs:在 Code.gs 中使用以下代码:
function doGet(request) {
Logger.log(request);
var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
var data = sheet.getDataRange().getValues();
var user = request.parameters.id;
var year = request.parameters.year;
for (var i=1; i<data.length; i++) {
if (data[i][0] == user[0]){
sheet.getRange(i+1, 3,1,1).setValue(year[0]);
}
}
var result = "Congratulations! You just said '" + year[0] + "' to " + user + ".";
var cell = sheet.getRange(1,1);
cell.setValue(year);
var cell = sheet.getRange(1,2);
cell.setValue(user);
return ContentService.createTextOutput(result);
}
Then Deploy - New Development - Choose WebApp然后部署 - 新开发 - 选择 WebApp
Copy the WebApp URL and add?id=John&year=9 to the end like this: https://script.google.com/macros/s/AKfymany numbercj/exec?id=John&year=9复制 WebApp URL 并将?id=John&year=9 添加到末尾,如下所示: https://script.google.com/macros/s/AKfymany numbercj/exec?id=John&year=9
Put that into a QR code generator and when that code is scanned, the name appears in the Google Sheet document.将其放入 QR 码生成器中,当扫描该代码时,该名称会出现在 Google Sheet 文档中。
When I looked at the original example, it appeared that two Google Sheet documents were being used, so I couldn't see the link between the two.当我查看原始示例时,似乎使用了两个 Google Sheet 文档,因此我看不到两者之间的链接。 In fact the scpript that becomes a WebApp is attached to the same Google Sheets document.事实上,成为 WebApp 的脚本附加到同一个 Google 表格文档。
Thanks again for the responses.再次感谢您的回复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.