谷歌表格-根据列标题将学生名册复制到新的表格中



我尝试过徒劳地寻找答案,希望我没有错过任何东西。如果过去有人问过这个问题,我很抱歉,但我现在陷入了困境:

我正在创建一个学生数据跟踪器供教师使用。这个想法是,他们会做几分钟的设置,输入他们的班级名称和学生名册,然后点击一个按钮,然后使用这些数据设置表格。

我已经找到了如何运行一个脚本来复制模板并根据类名列表重命名它,但我遇到的问题是让花名册自动复制。

名册被设置为一个数组,每个类有两列(名字和姓氏),类名使用索引自动填充在它们之上的合并列中。数据在单元格G2:D50中(为了美观起见,我现在有间隔列,但如果需要的话,可以删除它们)。由于这些表将继承显示在学生名称上方的类名,我认为必须有一种方法来说"取上面有"xx"名称的两列,并将第3-50行中的数据复制到这个新表中,从第x行开始使用相同的名称">

我总是可以使用导入范围或查询,但如果可能的话,希望数据自动粘贴为值。

非常感谢!

编辑-这里有一个链接到样品表

我将其放在示例文件的脚本中,并删除了将A7设置为公式的位置:

var studentRow = 4;
var studentColumn = 7 + (i*3);
var studentStartColumnName = NUM_RETURN_LETRA(studentColumn);
var lastRow = getFirstEmptyRowByColumnArray(studentStartColumnName) - 1;
var studentEndColumnName = NUM_RETURN_LETRA(studentColumn + 1);
var A1rangeString = studentStartColumnName + studentRow + ':' + studentEndColumnName + lastRow;
var studentRange = studentsSheet.getRange(A1rangeString);
//This will load the students into an Object.  You would push the students to a Range in the new sheet.activate
var students = getRowsData(studentsSheet, studentRange);
// It appears the students would be placed starting in cell A7 as Last Name and B7 as First Name
var newRange = currentSheet.getRange("A7:B");
var newValues = newRange.getValues();
//Loop through all the read students and place them in the new location in the correct format
for (s in students){
newValues[s][0] = students[s].lastName;
newValues[s][1] = students[s].firstName;
}
newRange.setValues(newValues);

我还在第二个脚本文件中添加了一些实用程序的代码。我将该文件命名为Utilities.gs。其中包括getRowsData()函数。

它应该还可以,但可能需要一点编辑才能在你的确切情况下工作。

相关内容

最新更新