The createTopTenSheets
AppScript automates the process of analyzing and organizing student test scores from a Google Sheet. It extracts student data from a designated sheet, sorts the scores by grade, and generates new sheets containing the top 10 test scores for each grade (9th–12th).
-
The script reads student data from a sheet named "All Students" starting at row 2, column B:
const data = allStudentsSheet.getRange(2, 2, allStudentsSheet.getLastRow(), 3).getValues();
-
It expects the following format:
- Headers:
Name
– Full name of the student (first and last name).Grade
– Grade level (9th–12th).Test Score
– Numeric test score (between 40–100).
- Headers:
-
The script processes the data as follows:
- Ignores the header row using
JSON.stringify()
:
const HEADER_ROW = JSON.stringify(["Name", "Grade", "Test Score"]);
- Filters out rows with empty values:
row.every(cell => cell)
- Converts grade and score to numeric values:
const grade = parseInt(row[ColumnIDs.GRADE], 10); const score = Number(row[ColumnIDs.SCORE]);
- Ignores the header row using
-
For each grade:
- If a sheet for that grade already exists, it is deleted and recreated.
- The script creates a new sheet named “9th Grade,” “10th Grade,” “11th Grade,” or “12th Grade.”
- Headers are added to the new sheet.
- Top 10 scores are added to the sheet.
- Columns are auto-resized for better display.
If the script processes the following input:
Name | Grade | Test Score |
---|---|---|
Alex Johnson | 9 | 88 |
Taylor Smith | 10 | 92 |
Jordan Lee | 9 | 95 |
Morgan Davis | 9 | 91 |
Riley Brown | 10 | 85 |
Jamie Miller | 12 | 97 |
Cameron Wilson | 11 | 93 |
Quinn Anderson | 12 | 94 |
Peyton Thomas | 11 | 86 |
Drew Martin | 10 | 95 |
Sydney White | 9 | 78 |
Avery Garcia | 11 | 88 |
"9th Grade" Sheet
Name | Grade | Test Score |
---|---|---|
Jordan Lee | 9 | 95 |
Morgan Davis | 9 | 91 |
Alex Johnson | 9 | 88 |
Sydney White | 9 | 78 |
"10th Grade" Sheet
Name | Grade | Test Score |
---|---|---|
Drew Martin | 10 | 95 |
Taylor Smith | 10 | 92 |
Riley Brown | 10 | 85 |
"11th Grade" Sheet
Name | Grade | Test Score |
---|---|---|
Cameron Wilson | 11 | 93 |
Avery Garcia | 11 | 88 |
Peyton Thomas | 11 | 86 |
"12th Grade" Sheet
Name | Grade | Test Score |
---|---|---|
Jamie Miller | 12 | 97 |
Quinn Anderson | 12 | 94 |
✅ Automates the process of sorting and organizing student data.
✅ Ensures consistent and reliable data handling.
✅ Eliminates manual work and human error.
✅ Provides a clear and organized view of top-performing students.
- Open your Google Sheet.
- Go to Extensions → Apps Script.
- Copy and paste the script.
- Save and authorize the script if prompted.
- Run the
createTopTenSheets
function from the Apps Script interface.
- Ensure that the "All Students" sheet is properly formatted with correct headers.
- Keep the test scores within the expected range (40–100).
- Remove any extra rows or columns that could interfere with data reading.