0

今年我在家教育 5 个孩子(我怎么那么老了?!)。长期以来,我一直试图简化出勤流程。

我想,"I'll use a Google Form that they will simply select their name and the date.(他们不能在出勤时欺骗我,因为它应该与时间戳匹配。嘘。) Here is the form: 谷歌出勤表格和谷歌出勤表格下拉

The information from the form presents in my Google sheet as: 谷歌表单数据

I have several students that have attendance sheets: 几个学生记录

My student record looks like this: 学生记录

我需要帮助:我需要在正确日期将 P 放入学生记录中,因为它已根据Google 表单数据中的信息进行验证。

I need this to repeat for all of my student records. To search the data from 谷歌表单数据 and put the P in the correct places.

我想我可能让它变得比它需要的更困难,或者我需要以不同的方式设置我的床单。

4

1 回答 1

0

您可以在 Sheets 中使用 Form Submit Installable 触发器,这样每当提交表单时,就会触发脚本函数来更新学生记录并在提交日期上放置“P”。

示例代码(您的 Google 表格中的入站脚本):

function UpdateStudentRecord(e) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var formValues = e.values;
 
  var name = formValues[1];
  var date = new Date(formValues[2]);

  var sheet = ss.getSheetByName(name);

  //Get Month Year String and the  day
  var timeZone = Session.getScriptTimeZone();
  var dateStr = Utilities.formatDate(date,timeZone, "MMMMM yyyy");
  var day = date.getDate().toString();
  
  //Find the row index of the submitted date 
  var colAValues = sheet.getRange('A1:A').getDisplayValues().flat();
  var rowIndex = colAValues.indexOf(dateStr);

  //Find the column index of the submitted day
  var row3Values = sheet.getRange("A3:3").getDisplayValues().flat();
  var colIndex = row3Values.indexOf(day);

  //Write P in the cell
  //Note that array index is in zero-based while sheet index is in one-based
  sheet.getRange(rowIndex+1, colIndex+1).setValue("P");
}

先决条件(创建表单提交触发器):

在此处输入图像描述

在此处输入图像描述

它能做什么?

  1. 每次提交表单时,UpdateStudentRecord()都会执行
  2. 获取事件对象中提交的表单值 e.values
  3. 获取学生姓名和提交日期
  4. 使用Utilities.formatDate(date, timeZone, format)以“月年”格式获取提交的日期字符串。并使用getDate()
  5. 获取所有 columnA 值,用于Array.flat()将二维数组更改为一维数组。使用Array.indexOf()搜索步骤 4 中获取的日期字符串
  6. 获取所有 Row3 值,用于Array.flat()将二维数组更改为一维数组。使用 [Array.indexOf()] 搜索在步骤 4 中获得的日期
  7. 使用setValue(value)在步骤 5 和 6 中获得的行和列索引上写入“P”

笔记:

在此示例代码中,工作表名称应与表单下拉列表中的学生姓名匹配。

输出:

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

于 2021-07-27T16:15:01.083 回答