function doGet(e) { return HtmlService.createHtmlOutputFromFile('display')…
- User
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
function doGet(e) { return HtmlService.createHtmlOutputFromFile('display') .setTitle('School Management System') .addMetaTag('viewport', 'width=device-width, initial-scale=1') .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL); }
/**
Creates the SchoolInfo sheet if it doesn't exist and populates it with default data. */ function createSchoolInfoSheet() { try { const ss = SpreadsheetApp.getActiveSpreadsheet(); let infoSheet = ss.getSheetByName('SchoolInfo');
// If the sheet doesn't exist, create it if (!infoSheet) { infoSheet = ss.insertSheet('SchoolInfo');
// Add headers const infoHeaders = ['Key', 'Value']; infoSheet.getRange(1, 1, 1, 2).setValues([infoHeaders]); infoSheet.getRange(1, 1, 1, 2).setFontWeight('bold');
// Add default data const infoData = [ ['Name of School', 'M.T.T.C. PRACTICE PRIMARY SCHOOL'], ['Address', 'POST OFFICE BOX 379'], ['Location', 'MAMPONG-ASHANTI'], ['HeadmasterName', 'MR. EDMUND BEDIAKO'], ['Email', [EMAIL_ADDRESS]'], ['Phone', '[PHONE_NUMBER]'], ['Logo1Url', 'https://i.imgur.com/l9dDRok.png'], ['Logo2Url', 'https://imgur.com/N0sEqK0.png'], ['HeadmasterSignatureUrl', 'https://imgur.com/8ZT89ln.png'], ['term', 'Second Term'], ['academicYear', '2024/2025'], ['reopenDate', '06-05-2025'] ];
infoSheet.getRange(2, 1, infoData.length, 2).setValues(infoData);
// Format the sheet infoSheet.autoResizeColumns(1, 2); }
return true; } catch (error) { Logger.log('Error in createSchoolInfoSheet: ' + error.message); throw new Error('Failed to create SchoolInfo sheet: ' + error.message); } }
/**
Retrieves school metadata from the SchoolInfo sheet
@return {Object} School metadata including term, academic year, reopen date, etc. */ function getSchoolMetadata() { try { const ss = SpreadsheetApp.getActiveSpreadsheet(); let metadataSheet = ss.getSheetByName('SchoolInfo');
if (!metadataSheet) { Logger.log('SchoolInfo sheet not found, creating it now.'); createSchoolInfoSheet(); metadataSheet = ss.getSheetByName('SchoolInfo');
if (!metadataSheet) { throw new Error('Failed to create SchoolInfo sheet'); } }
const metadataValues = metadataSheet.getDataRange().getValues(); const metadata = {};
// Convert 2D array to object with key-value pairs for (let i = 1; i < metadataValues.length; i++) { if (metadataValues[i][0] && metadataValues[i][1] !== undefined) { metadata[metadataValues[i][0]] = metadataValues[i][1]; } }
// Check for required metadata fields and provide defaults if missing const requiredFields = [ "Name of School", "Address", "Location", "HeadmasterName", "Email", "Phone", "Logo1Url", "Logo2Url", "HeadmasterSignatureUrl", "term", "academicYear", "reopenDate" ];
const defaults = { "Name of School": "M.T.T.C. PRACTICE PRIMARY SCHOOL", "Address": "POST OFFICE BOX 379", "Location": "MAMPONG-ASHANTI", "HeadmasterName": "MR. EDMUND BEDIAKO", "Email": "[EMAIL_ADDRESS]", "Phone": "[PHONE_NUMBER]", "Logo1Url": "https://i.imgur.com/l9dDRok.png", "Logo2Url": "https://imgur.com/N0sEqK0.png", "HeadmasterSignatureUrl": "https://imgur.com/8ZT89ln.png", "term": "Second Term", "academicYear": "2024/2025", "reopenDate": "06-05-2025" };
for (const field of requiredFields) { if (!metadata[field]) { metadata[field] = defaults[field]; } }
return metadata; } catch (error) { Logger.log('Error in getSchoolMetadata: ' + error.message); // Return default values in case of error return { "Name of School": "M.T.T.C. PRACTICE PRIMARY SCHOOL", "Address": "POST OFFICE BOX 379", "Location": "MAMPONG-ASHANTI", "HeadmasterName": "MR. EDMUND BEDIAKO", "Email": "[EMAIL_ADDRESS]", "Phone": "[PHONE_NUMBER]", "Logo1Url": "https://i.imgur.com/l9dDRok.png", "Logo2Url": "https://imgur.com/N0sEqK0.png", "HeadmasterSignatureUrl": "https://imgur.com/8ZT89ln.png", "term": "Second Term", "academicYear": "2024/2025", "reopenDate": "06-05-2025" }; } }
/**
Retrieves data from a specific sheet
@param {string} sheetName - Name of the sheet to retrieve data from
@param {string} recordCount - Number of records to retrieve or 'all'
@return {Array} 2D array of sheet data */ function getSheetData(sheetName, recordCount) { try { const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheetByName(sheetName);
if (!sheet) {
throw new Error(Sheet "${sheetName}" not found.);
}
const dataRange = sheet.getDataRange(); const values = dataRange.getValues();
// Check if we have any data if (values.length <= 1) { return [values[0]]; // Return just the header row if that's all we have }
if (recordCount === 'all') { return values; } else { const count = parseInt(recordCount, 10); // Make sure we don't try to return more rows than exist const maxRows = Math.min(count + 1, values.length); return values.slice(0, maxRows); // +1 to include header row } } catch (error) { Logger.log('Error in getSheetData: ' + error.message); throw new Error('Failed to retrieve sheet data: ' + error.message); } }
/**
Gets all students for a given class
@param {string} className - The class name
@return {Array} Array of student objects with id and name */ function getAllStudents(className) { try { const ss = SpreadsheetApp.getActiveSpreadsheet();
// Define class-subject mapping const classSubjects = { 'KGOne': ['Literacy'], 'KGTwo': ['Literacy'], 'BasicOne': ['Mathematics'], 'BasicTwo': ['Mathematics'], 'BasicThree': ['Mathematics'], 'BasicFour': ['Mathematics'], 'BasicFive': ['Mathematics'], 'BasicSix': ['Mathematics'] };
const sheetMapping = { KGOne: { Literacy: 'Literacy' }, KGTwo: { Literacy: 'LiteracyKG2' }, BasicOne: { Mathematics: 'BS1Mathematics' }, BasicTwo: { Mathematics: 'BS2Mathematics' }, BasicThree: { Mathematics: 'BS3Mathematics' }, BasicFour: { Mathematics: 'BS4Mathematics' }, BasicFive: { Mathematics: 'BS5Mathematics' }, BasicSix: { Mathematics: 'BS6Mathematics' } };
if (!classSubjects[className]) {
throw new Error(Class "${className}" not found.);
}
// Use the first subject in the class to get all students const subject = classSubjects[className][0]; const sheetName = sheetMapping[className][subject]; const sheet = ss.getSheetByName(sheetName);
if (!sheet) {
throw new Error(Sheet "${sheetName}" not found.);
}
const data = sheet.getDataRange().getValues(); const students = [];
// Skip header row for (let i = 1; i < data.length; i++) { if (data[i][0] && data[i][1]) { // Make sure ID and Name exist students.push({ id: data[i][0], name: data[i][1] }); } }
return students; } catch (error) { Logger.log('Error in getAllStudents: ' + error.message); throw new Error('Failed to retrieve students: ' + error.message); } }
/**
Retrieves data for a specific student across all subjects
@param {string} studentId - Student ID
@param {string} className - Class name
@return {Object} Student data including scores for all subjects */ function getStudentData(studentId, className) { try { const ss = SpreadsheetApp.getActiveSpreadsheet(); studentId = parseInt(studentId, 10);
// Define class-subject mapping const classSubjects = { 'KGOne': ['Literacy', 'Numeracy', 'Creative Arts', 'Our World Our People'], 'KGTwo': ['Literacy', 'Numeracy', 'Creative Arts', 'Our World Our People'], 'BasicOne': ['Mathematics', 'English', 'Science', 'History', 'Creative Arts', 'RME', 'Asante Twi'], 'BasicTwo': ['Mathematics', 'English', 'Science', 'History', 'Creative Arts', 'RME', 'Asante Twi'], 'BasicThree': ['Mathematics', 'English', 'Science', 'History', 'Creative Arts', 'RME', 'Asante Twi'], 'BasicFour': ['Mathematics', 'English', 'Science', 'History', 'Creative Arts', 'RME', 'Asante Twi', 'Computing'], 'BasicFive': ['Mathematics', 'English', 'Science', 'History', 'Creative Arts', 'RME', 'Asante Twi', 'Computing'], 'BasicSix': ['Mathematics', 'English', 'Science', 'History', 'Creative Arts', 'RME', 'Asante Twi', 'Computing'] };
const sheetMapping = { KGOne: { Literacy: 'Literacy', Numeracy: 'Numeracy', 'Creative Arts': 'Creative', 'Our World Our People': 'Our World Our People' }, KGTwo: { Literacy: 'LiteracyKG2', Numeracy: 'NumeracyKG2', 'Creative Arts': 'CreativeKG2', 'Our World Our People': 'Our World Our People.' }, BasicOne: { Mathematics: 'BS1Mathematics', English: 'BS1English', Science: 'BS1Science', History: 'BS1History', 'Creative Arts': 'BS1Creative', RME: 'BS1Religious', 'Asante Twi': 'BS1Asante Twi' }, BasicTwo: { Mathematics: 'BS2Mathematics', English: 'BS2English', Science: 'BS2Science', History: 'BS2History', 'Creative Arts': 'BS2Creative', RME: 'BS2Religious', 'Asante Twi': 'BS2Asante Twi' }, BasicThree: { Mathematics: 'BS3Mathematics', English: 'BS3English', Science: 'BS3Science', History: 'BS3History', 'Creative Arts': 'BS3Creative', RME: 'BS3Religious', 'Asante Twi': 'BS3Asante Twi' }, BasicFour: { Mathematics: 'BS4Mathematics', English: 'BS4English', Science: 'BS4Science', History: 'BS4History', 'Creative Arts': 'BS4Creative', RME: 'BS4Religious', 'Asante Twi': 'BS4Asante Twi', Computing: 'BS4Computing' }, BasicFive: { Mathematics: 'BS5Mathematics', English: 'BS5English', Science: 'BS5Science', History: 'BS5History', 'Creative Arts': 'BS5Creative', RME: 'BS5Religious', 'Asante Twi': 'BS5Asante Twi', Computing: 'BS5Computing' }, BasicSix: { Mathematics: 'BS6Mathematics', English: 'BS6English', Science: 'BS6Science', History: 'BS6History', 'Creative Arts': 'BS6Creative', RME: 'BS6Religious', 'Asante Twi': 'BS6Asante Twi', Computing: 'BS6Computing' } };
if (!classSubjects[className]) {
throw new Error(Class "${className}" not found.);
}
const subjects = classSubjects[className]; const studentData = { subjects: [] };
/**
/**
Prints all reports for a class
@param {string} className - The class name
@return {string} URL to the printable document */ function printAllReports(className) { try { const students = getAllStudents(className); if (students.length === 0) { throw new Error('No students found for this class'); }
// Get school metadata const metadata = getSchoolMetadata();
// Create a new Google Doc for printing
const docTitle = ${className} Reports - ${metadata.academicYear} - ${metadata.term};
const doc = DocumentApp.create(docTitle);
const body = doc.getBody();
// Add header to document body.appendParagraph(metadata["Name of School"]) .setHeading(DocumentApp.ParagraphHeading.HEADING1) .setAlignment(DocumentApp.HorizontalAlignment.CENTER);
body.appendParagraph(Class: ${className} | Term: ${metadata.term} | Academic Year: ${metadata.academicYear})
.setAlignment(DocumentApp.HorizontalAlignment.CENTER);
body.appendParagraph(Generated on: ${new Date().toLocaleDateString()})
.setAlignment(DocumentApp.HorizontalAlignment.CENTER);
body.appendHorizontalRule();
// Create reports for each student
for (let i = 0; i < students.length; i++) {
const student = students[i];
Logger.log(Processing student ${i+1}/${students.length}: ${student.name});
try { const studentData = getStudentData(student.id, className);
// Add student report to document
body.appendParagraph(`Student Report: ${studentData.name}`)
.setHeading(DocumentApp.ParagraphHeading.HEADING2);
// Basic student info
const infoTable = body.appendTable([
['ID:', studentData.id.toString()],
['Class:', className],
['Academic Year:', metadata.academicYear],
['Term:', metadata.term],
['Attendance:', studentData.attendance || 'N/A'],
['Position:', studentData.position ? getPositionSuffix(studentData.position) : 'N/A']
]);
formatTable(infoTable);
// Add subject scores
body.appendParagraph('Subject Scores')
.setHeading(DocumentApp.ParagraphHeading.HEADING3);
const scoreTableHeader = ['Subject', 'Class Score', 'Exam Score', 'Total', 'Grade', 'Position', 'Remarks'];
const scoreTableRows = [scoreTableHeader];
for (const subject of studentData.subjects) {
scoreTableRows.push([
subject.name,
subject.classScore.toString(),
subject.examScore.toString(),
subject.totalScore.toString(),
subject.grade,
subject.position ? subject.position.toString() : 'N/A',
subject.remarks
]);
}
const scoreTable = body.appendTable(scoreTableRows);
formatTable(scoreTable, true);
// Add comments section
body.appendParagraph('Teacher\'s Comments:')
.setHeading(DocumentApp.ParagraphHeading.HEADING3);
body.appendParagraph(studentData.formMasterRemarks || 'No comments provided.');
body.appendParagraph('Head Teacher\'s Comments:')
.setHeading(DocumentApp.ParagraphHeading.HEADING3);
body.appendParagraph(studentData.headMasterRemarks || 'No comments provided.');
// Add promotion info if available
if (studentData.promoted || studentData.promotedTo) {
body.appendParagraph('Promotion:')
.setHeading(DocumentApp.ParagraphHeading.HEADING3);
const promotionText = studentData.promotedTo ?
`Promoted to ${studentData.promotedTo}` :
(studentData.promoted === 'Yes' ? 'Promoted' : 'Not Promoted');
body.appendParagraph(promotionText);
}
// Add page break after each student except the last one
if (i < students.length - 1) {
body.appendPageBreak();
}
/**
// If the table has a header, format it if (hasHeader) { const header = table.getRow(0); for (let i = 0; i < header.getNumCells(); i++) { const cell = header.getCell(i); cell.setBackgroundColor('#4a86e8'); cell.getChild(0).asParagraph().setFontColor('#ffffff'); } }
// Auto-fit the table to the content for (let i = 0; i < table.getNumRows(); i++) { for (let j = 0; j < table.getRow(i).getNumCells(); j++) { table.getRow(i).getCell(j).getParagraph().setAlignment(DocumentApp.HorizontalAlignment.CENTER); } } }
/**
switch (position % 10) { case 1: return position + "st"; case 2: return position + "nd"; case 3: return position + "rd"; default: return position + "th"; } }
/**
Create all necessary sheets for a new class
@param {string} className - Name of the class to create
@return {boolean} Success status */ function createClassSheets(className) { try { const ss = SpreadsheetApp.getActiveSpreadsheet();
// Define subjects for different class levels const classSubjects = { 'KGOne': ['Literacy', 'Numeracy', 'Creative Arts', 'Our World Our People'], 'KGTwo': ['Literacy', 'Numeracy', 'Creative Arts', 'Our World Our People'], 'BasicOne': ['Mathematics', 'English', 'Science', 'History', 'Creative Arts', 'RME', 'Asante Twi'], 'BasicTwo': ['Mathematics', 'English', 'Science', 'History', 'Creative Arts', 'RME', 'Asante Twi'], 'BasicThree': ['Mathematics', 'English', 'Science', 'History', 'Creative Arts', 'RME', 'Asante Twi'], 'BasicFour': ['Mathematics', 'English', 'Science', 'History', 'Creative Arts', 'RME', 'Asante Twi', 'Computing'], 'BasicFive': ['Mathematics', 'English', 'Science', 'History', 'Creative Arts', 'RME', 'Asante Twi', 'Computing'], 'BasicSix': ['Mathematics', 'English', 'Science', 'History', 'Creative Arts', 'RME', 'Asante Twi', 'Computing'] };
const sheetMapping = { KGOne: { Literacy: 'Literacy', Numeracy: 'Numeracy', 'Creative Arts': 'Creative', 'Our World Our People': 'Our People' }, KGTwo: { Literacy: 'LiteracyKG2', Numeracy: 'NumeracyKG2', 'Creative Arts': 'CreativeKG2', 'Our World Our People': 'Our World' }, BasicOne: { Mathematics: 'BS1Mathematics', English: 'BS1English', Science: 'BS1Science', History: 'BS1History', 'Creative Arts': 'BS1Creative', RME: 'BS1Religious', 'Asante Twi': 'BS1Asante Twi' }, BasicTwo: { Mathematics: 'BS2Mathematics', English: 'BS2English', Science: 'BS2Science', History: 'BS2History', 'Creative Arts': 'BS2Creative', RME: 'BS2Religious', 'Asante Twi': 'BS2Asante Twi' }, BasicThree: { Mathematics: 'BS3Mathematics', English: 'BS3English', Science: 'BS3Science', History: 'BS3History', 'Creative Arts': 'BS3Creative', RME: 'BS3Religious', 'Asante Twi': 'BS3Asante Twi' }, BasicFour: { Mathematics: 'BS4Mathematics', English: 'BS4English', Science: 'BS4Science', History: 'BS4History', 'Creative Arts': 'BS4Creative', RME: 'BS4Religious', 'Asante Twi': 'BS4Asante Twi', Computing: 'BS4Computing' }, BasicFive: { Mathematics: 'BS5Mathematics', English: 'BS5English', Science: 'BS5Science', History: 'BS5History', 'Creative Arts': 'BS5Creative', RME: 'BS5Religious', 'Asante Twi': 'BS5Asante Twi', Computing: 'BS5Computing' }, BasicSix: { Mathematics: 'BS6Mathematics', English: 'BS6English', Science: 'BS6Science', History: 'BS6History', 'Creative Arts': 'BS6Creative', RME: 'BS6Religious', 'Asante Twi': 'BS6Asante Twi', Computing: 'BS6Computing' } };
if (!classSubjects[className]) {
throw new Error(Invalid class name: "${className}");
}
// Create sheets for each subject const subjects = classSubjects[className];
for (const subject of subjects) { const sheetName = sheetMapping[className][subject];
// Check if sheet already exists if (ss.getSheetByName(sheetName)) { Logger.log(); continue; }
body {
font-family: var(--font-family);
margin: 0;
padding: 0;
background-color: #f0f2f5;
color: var(--dark-color);
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.header {
background-color: var(--primary-color);
color: white;
padding: 15px 20px;
display: flex;
justify-content: space-between;
align-items: center;
border-bottom: 3px solid var(--secondary-color);
border-radius: 5px 5px 0 0;
}
.header h1 {
margin: 0;
font-size: 1.8rem;
}
.login-container {
background-color: white;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
padding: 2rem;
max-width: 400px;
margin: 5rem auto;
}
.content-area {
background-color: white;
border-radius: 0 0 5px 5px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
padding: 20px;
margin-bottom: 20px;
}
.control-panel {
display: flex;
flex-wrap: wrap;
gap: 15px;
margin-bottom: 20px;
padding: 15px;
background-color: #f9f9f9;
border-radius: 5px;
border: 1px solid #e0e0e0;
Your Google Apps Script code is designed to manage various aspects of a school management system, including handling HTTP GET requests, creating and managing spreadsheets for school information, retrieving student data, and generating reports. Here's an overview of the key functions and their purposes:
doGet(e) Function:
createSchoolInfoSheet() Function:
getSchoolMetadata() Function:
createSchoolInfoSheet() to create and populate it.getSheetData(sheetName, recordCount) Function:
recordCount is 'all'; otherwise, returns the specified number of records.getAllStudents(className) Function:
getStudentData(studentId, className) Function:
calculateRemark(score) Function:
// Get school metadata const metadata = getSchoolMetadata();
// Get all students for this class to calculate total number of students const allStudents = getAllStudents(className); studentData.totalStudents = allStudents.length;
// Get basic student info from the first subject sheet const firstSubject = subjects[0]; const firstSheetName = sheetMapping[className][firstSubject]; const firstSheet = ss.getSheetByName(firstSheetName);
if (!firstSheet) {
throw new Error(Sheet "${firstSheetName}" not found.);
}
const firstSheetData = firstSheet.getDataRange().getValues(); let studentRow = null;
for (let i = 1; i < firstSheetData.length; i++) { if (firstSheetData[i][0] === studentId) { studentRow = firstSheetData[i]; break; } }
if (!studentRow) {
throw new Error(Student with ID "${studentId}" not found.);
}
// Set basic student info studentData.id = studentId; studentData.name = studentRow[1]; // Assuming name is in column B (index 1) studentData.attendance = studentRow[13]; // Attendance column studentData.interest = studentRow[14]; // Interest column studentData.conduct = studentRow[15]; // Conduct column studentData.formMasterRemarks = studentRow[16]; // Form Master's Remarks column studentData.headMasterRemarks = studentRow[17]; // Head Master's Remarks column studentData.promoted = studentRow[18]; // PROMOTED column studentData.promotedTo = studentRow[19]; // CLASS PROMOTED TO column
// Calculate position (overall for the class) const studentScores = {};
// First, get total scores for all students across all subjects for (const student of allStudents) { const studentId = student.id; studentScores[studentId] = { name: student.name, totalScore: 0, subjectCount: 0 }; }
// Calculate total scores for each student across all subjects for (const subject of subjects) { const sheetName = sheetMapping[className][subject]; const sheet = ss.getSheetByName(sheetName);
if (!sheet) {
Logger.log(Sheet "${sheetName}" not found. Skipping subject "${subject}".);
continue;
}
const sheetData = sheet.getDataRange().getValues();
for (let i = 1; i < sheetData.length; i++) { const id = sheetData[i][0]; if (studentScores[id]) { const totalScore = sheetData[i][10]; // TOTAL (A+B) column if (!isNaN(totalScore) && totalScore !== null && totalScore !== "") { studentScores[id].totalScore += parseFloat(totalScore); studentScores[id].subjectCount++; } } } }
// Convert to array and sort by total score const studentList = Object.keys(studentScores).map(id => ({ id: parseInt(id), name: studentScores[id].name, totalScore: studentScores[id].totalScore, averageScore: studentScores[id].subjectCount > 0 ? studentScores[id].totalScore / studentScores[id].subjectCount : 0 }));
studentList.sort((a, b) => b.totalScore - a.totalScore);
// Find position of our student const position = studentList.findIndex(s => s.id === studentId) + 1; studentData.position = position;
// Get subject scores for (const subject of subjects) { const sheetName = sheetMapping[className][subject]; const sheet = ss.getSheetByName(sheetName);
if (!sheet) {
Logger.log(Sheet "${sheetName}" not found. Skipping subject "${subject}".);
continue;
}
const sheetData = sheet.getDataRange().getValues(); let subjectRow = null;
for (let i = 1; i < sheetData.length; i++) { if (sheetData[i][0] === studentId) { subjectRow = sheetData[i]; break; } }
if (subjectRow) { // Sort students by score for this subject to determine position const subjectStudents = []; for (let i = 1; i < sheetData.length; i++) { if (sheetData[i][0] && sheetData[i][10] !== null && sheetData[i][10] !== "") { subjectStudents.push({ id: sheetData[i][0], score: parseFloat(sheetData[i][10]) }); } }
subjectStudents.sort((a, b) => b.score - a.score);
const subjectPosition = subjectStudents.findIndex(s => s.id === studentId) + 1;
studentData.subjects.push({
name: subject,
classScore: Math.round(subjectRow[7]), // SCALE A TO (50%)
examScore: Math.round(subjectRow[9]), // SCALE B TO (50%)
totalScore: Math.round(subjectRow[10]), // TOTAL (A+B) 100
grade: subjectRow[11], // GRADE
position: subjectPosition, // Calculate position for this subject
remarks: calculateRemark(subjectRow[10]) // Calculate remarks based on total score
});
} }
return studentData; } catch (error) { Logger.log('Error in getStudentData: ' + error.message); throw new Error('Failed to retrieve student data: ' + error.message); } }
} catch (studentError) {
Logger.log(Error processing student ${student.name}: ${studentError.message});
body.appendParagraph(Error generating report for ${student.name}: ${studentError.message})
.setFontColor('#FF0000');
if (i < students.length - 1) {
body.appendPageBreak();
}
} }
// Save and close the document doc.saveAndClose();
// Return the URL to the document return doc.getUrl(); } catch (error) { Logger.log('Error in printAllReports: ' + error.message); throw new Error('Failed to print reports: ' + error.message); } }
Sheet "${sheetName}" already exists. Skipping.// Create new sheet const sheet = ss.insertSheet(sheetName);
// Add headers const headers = [ 'S/N', 'Full Name', 'Test 1 (15)', 'Group Work (15)', 'Test 2 (15)', 'Project Work (15)', 'Total A (60)', 'SCALE A TO (50%)', 'EXAMS SCORE B (100)', 'SCALE B TO (50%)', 'TOTAL (A+B) 100', 'GRADE', 'POSITION', 'Attendance', 'Interest', 'Conduct', 'Form Master's Remarks', 'Head Master's Remarks', 'PROMOTED', 'CLASS PROMOTED TO', '', 'Term', 'Academic Year', 'Reopen Date' ];
sheet.getRange(1, 1, 1, headers.length).setValues([headers]);
// Format the sheet sheet.getRange(1, 1, 1, headers.length).setFontWeight('bold'); sheet.setFrozenRows(1);
// Add formulas for automatic calculations // These will be added when data is actually input }
// Ensure SchoolInfo sheet exists createSchoolInfoSheet();
return true; } catch (error) { Logger.log('Error in createClassSheets: ' + error.message); throw new Error('Failed to create class sheets: ' + error.message); } }
printAllReports(className) Function:
formatTable(table, hasHeader) Function:
hasHeader is true.getPositionSuffix(position) Function:
createClassSheets(className) Function:
This script effectively integrates various Google Workspace services, such as Sheets, Docs, and Gmail, to automate and manage school-related data and processes. By leveraging Google Apps Script, you can streamline administrative tasks, enhance data management, and improve overall efficiency within the school management system.
For further exploration and examples of using Google Apps Script in educational settings, you might find the following resources helpful:
Automating ID Card Creation and Emailing: This article demonstrates how to create ID cards for students using Google Apps Script, Google Forms, and Google Sheets, and then send them via email[1].
Comprehensive Guide to Google Apps Script for Google Workspace: This guide covers the fundamentals, practical examples, exercises, and quiz questions to master Google Workspace automation[2].
Apps Script Samples Overview: This resource provides various Apps Script quickstarts, solutions, and codelabs to help you get started with different projects[3].
These resources offer practical examples and insights into how Google Apps Script can be utilized to enhance educational processes and administrative tasks.