[英]Add button to update Google Spreadsheet. Increment cell and update another cell with current date
We have spreadsheet that has a list of members at our gym facility. 我们有一个电子表格,其中包含我们健身房设施中的成员列表。 What we would like to incorporate is a way that a coach could walk around with an iPad and click a button that would "check-in" our members.
我们希望采用的一种方法是,教练可以带着iPad走来走去,然后单击“签到”我们的会员的按钮。 Usually the number of members present is small - maybe 20-30 members per class.
通常,出席的成员人数很少-每个班级可能只有20-30名成员。 But, we want a way to try to have coach accountability so if someone doesn't show up for 3 weeks, we can reach out in an email to inquire where they have been.
但是,我们希望有一种方法来尝试对教练负责,因此,如果某人没有出现3个星期,我们可以通过电子邮件与他们联系,询问他们去过的地方。
I've created a test spreadsheet that should be editable. 我已经创建了一个可编辑的测试电子表格。 I need some help with recommendations or writing a script that would perform the following:
我需要一些建议或编写脚本来执行以下操作:
What I would like is a button in the far left "check-in" column next to every member name that our coaches could click when they are present. 我想在最左边的“签到”列中有一个按钮,旁边有我们的教练在场时可以点击的每个会员名称。 What that would do would add +1 to the "total check-ins" column and also update the "last time checked-in" column with the current date/time stamp.
这样做会在“总签到”列中添加+1,并使用当前日期/时间戳更新“上次签到时间”列。
https://docs.google.com/spreadsheet/ccc?key=0AnGxNda7E77DdHZldlhQY2hZZlNJamZ6VTZ0WUhqZXc&usp=sharing https://docs.google.com/spreadsheet/ccc?key=0AnGxNda7E77DdHZldlhQY2hZZlNJamZ6VTZ0WUhqZXc&usp=sharing
I'm brand new to scripting in Google Docs, so thanks in advance for any expertise that is offered! 我是Google文档中脚本编制的新手,所以在此先感谢您提供的任何专业知识! MUCH appreciated!
非常感激!
Here you go 干得好
Spreadsheet https://docs.google.com/spreadsheet/ccc?key=0AvmOEVr803HMdDE5MmZXMlQ1cnpzQ21wYkNNZ19ENXc#gid=0 电子表格https://docs.google.com/spreadsheet/ccc?key=0AvmOEVr803HMdDE5MmZXMlQ1cnpzQ21wYkNNZ19ENXc#gid=0
Script UI (Open this url from any device like Serge said.) https://script.google.com/macros/s/AKfycbxfqII2qhtctJTO1nVyLOBZJ4KxElVh8I3fTCFUR1o5R1uOUcA/exec 脚本用户界面(从Serge所说的任何设备打开此URL。) https://script.google.com/macros/s/AKfycbxfqII2qhtctJTO1nVyLOBZJ4KxElVh8I3fTCFUR1o5R1uOUcA/exec
Code: 码:
function doGet() {
var ss = SpreadsheetApp.openById('0AvmOEVr803HMdDE5MmZXMlQ1cnpzQ21wYkNNZ19ENXc');
var sheet = ss.getSheetByName('members');
var members = sheet.getRange(2, 1, sheet.getLastRow()-1, 1).getValues();
Logger.log(members)
var app = UiApp.createApplication().setTitle('Gym Check In');
var grid = app.createFlexTable().setId('grid');
app.add(grid);
var row = 0;
var column = 0;
for (var m in members) {
grid.setWidget(row, 0, app.createLabel(members[m]));
grid.setWidget(row, 1, app.createButton('Check In').setId(row+2).addClickHandler(app.createServerHandler('checkIn').addCallbackElement(grid)).addClickHandler(app.createClientHandler().forEventSource().setEnabled(false)));
row++;
}
return app;
}
function checkIn(e) {
var ss = SpreadsheetApp.openById('0AvmOEVr803HMdDE5MmZXMlQ1cnpzQ21wYkNNZ19ENXc');
var sheet = ss.getSheetByName('members');
var button = e.parameter.source;
sheet.getRange(button, 2).setValue(new Date());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.