Thanks for sharing the script! This is a solid implementation that:
Checks filename matches student name
Extracts CGPA and semester from CV text
Matches against official rank list data
Checks if "rank" word is mentioned (not allowed)
Checks CV page count (max 2)
Checks font size (must be 12) and font family (Times New Roman or Garamond)
Writes PASS/FAIL and remarks in the sheet
Checks filename matches student name
Extracts CGPA and semester from CV text
Matches against official rank list data
Checks if "rank" word is mentioned (not allowed)
Checks CV page count (max 2)
Checks font size (must be 12) and font family (Times New Roman or Garamond)
Writes PASS/FAIL and remarks in the sheet
What I notice / suggestions for next steps:
Status and remarks columns:You setstatusCol = headers.lengthso the status goes in the first empty column after existing headers.But you write status in columnstatusCol + 1and remarks instatusCol + 2—Just verify your sheet layout to confirm these columns are empty and okay for writing.
Google Drive API usage:You useDrive.Files.copyto convert to Google Doc — this requires enabling theDrive API advanced servicein Apps Script:In Apps Script Editor:Services > + Add Service > Drive APIYour script needs permission scopes for calls.
In Apps Script Editor:Services > + Add Service > Drive API
Your script needs permission scopes for calls.
Page count function:Parsing PDF content as text to find/Type /Pageentries is a known trick, but it can be unreliable for some PDFs. If you have errors there, consider a different approach or skip page count.
Font size and family check:You check font size and font family paragraph by paragraph — good! If you want stricter control, you might check each TextElement run inside paragraphs, but that adds complexity.
Status and remarks columns:You setstatusCol = headers.lengthso the status goes in the first empty column after existing headers.But you write status in columnstatusCol + 1and remarks instatusCol + 2—Just verify your sheet layout to confirm these columns are empty and okay for writing.
Google Drive API usage:You useDrive.Files.copyto convert to Google Doc — this requires enabling theDrive API advanced servicein Apps Script:
In Apps Script Editor:Services > + Add Service > Drive API
Your script needs permission scopes for calls.
In Apps Script Editor:Services > + Add Service > Drive API
Your script needs permission scopes for calls.
Page count function:Parsing PDF content as text to find/Type /Pageentries is a known trick, but it can be unreliable for some PDFs. If you have errors there, consider a different approach or skip page count.
Font size and family check:You check font size and font family paragraph by paragraph — good! If you want stricter control, you might check each TextElement run inside paragraphs, but that adds complexity.
Improvements / fixes you may want:
Avoid duplicate columns on multiple runs:YourstatusCol = headers.lengthassumes no previous validation columns; if you run multiple times, you get multiple status columns. Better to fix a specific column by name, e.g., "Validation Status", "Remarks" and add them if missing.
Clean up temporary Google Docs after processing:Your code converts PDF to Google Doc copy for reading. This leaves temp docs behind. You can delete these after validation to avoid clutter.
Handle CVs in Word (.docx) or PDF formats:Your script assumes PDFs converted to Google Docs; Word files might need a different approach.
Avoid duplicate columns on multiple runs:YourstatusCol = headers.lengthassumes no previous validation columns; if you run multiple times, you get multiple status columns. Better to fix a specific column by name, e.g., "Validation Status", "Remarks" and add them if missing.
Clean up temporary Google Docs after processing:Your code converts PDF to Google Doc copy for reading. This leaves temp docs behind. You can delete these after validation to avoid clutter.
Handle CVs in Word (.docx) or PDF formats:Your script assumes PDFs converted to Google Docs; Word files might need a different approach.
Here's an enhanced version of your script with some fixes:
────────────────────────────────────────────────────────────────────
javascriptCopy codefunction validateCVs() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const formSheet = ss.getSheetByName("Form Responses 1");
const rankSheet = ss.getSheetByName("RankList");
const rankData = rankSheet.getDataRange().getValues(); // [Name, CGPA, Semester]
// Ensure columns for status and remarks exist, or add them
let headers = formSheet.getRange(1, 1, 1, formSheet.getLastColumn()).getValues()[0];
let statusCol = headers.indexOf("Validation Status");
let remarksCol = headers.indexOf("Remarks");
if (statusCol === -1) {
statusCol = headers.length;
formSheet.getRange(1, statusCol + 1).setValue("Validation Status");
}
if (remarksCol === -1) {
remarksCol = headers.length === statusCol ? headers.length + 1 : headers.length;
formSheet.getRange(1, remarksCol + 1).setValue("Remarks");
}
const nameCol = headers.indexOf("Full Name");
const fileUrlCol = Your CV");
const responses = formSheet.getDataRange().getValues();
for (let i = 1; i < responses.length; i++) {
const name = responses[i][nameCol]?.trim();
const fileUrl = responses[i][fileUrlCol];
const currentStatus = responses[i][statusCol];
if (!fileUrl || currentStatus) continue; // Skip if no CV or already processed
try {
const fileId = getFileIdFromUrl(fileUrl);
const originalFile = DriveApp.getFileById(fileId);
// Filename match check
const expectedName = name.replace(/\s+/g, ' ').trim().toLowerCase();
if (!originalFile.getName().toLowerCase().includes(expectedName)) {
formSheet.getRange(i + 1, statusCol + 1).setValue("FAIL");
formSheet.getRange(i + 1, remarksCol + 1).setValue("Filename mismatch.");
continue;
}
// Convert file to Google Doc (requires Drive API enabled)
const copiedDoc = Drive.Files.copy({}, fileId, { convert: true });
const docId = copiedDoc.id;
const doc = DocumentApp.openById(docId);
const docBody = doc.getBody();
const text = docBody.getText();
const { cgpa, semester } = extractCGPAandSemester(text);
const match = rankData.find(row => row[0].toLowerCase().trim() === name.toLowerCase().trim());
let status = "PASS";
let remarks = [];
if (!match) {
status = "FAIL";
remarks.push("Name not found in rank list.");
} else {
const [_, officialCgpa, officialSem] = match;
if (cgpa === null || Math.abs(parseFloat(cgpa) - parseFloat(officialCgpa)) > 0.01) {
status = "FAIL";
remarks.push(`CGPA mismatch. Found: ${cgpa}, Expected: ${officialCgpa}`);
}
if (semester === null || semester !== parseInt(officialSem)) {
status = "FAIL";
remarks.push(`Semester mismatch. Found: ${semester}, Expected: ${officialSem}`);
}
}
if (text.toLowerCase().includes("rank")) {
status = "FAIL";
remarks.push("Mention of rank is not allowed.");
}
// Page count check on PDF copy
const pdfBlob = DriveApp.getFileById(fileId).getBlob().getAs("application/pdf");
const pageCount = getPdfPageCount(pdfBlob);
if (pageCount > 2) {
status = "FAIL";
remarks.push(`CV exceeds 2 pages (Found ${pageCount})`);
}
// Font checks
const paragraphs = docBody.getParagraphs();
for (const p of paragraphs) {
const size = p.getFontSize();
const font = p.getFontFamily();
const textLine = p.getText().trim();
if (!textLine) continue;
if (size !== 12) {
status = "FAIL";
remarks.push(`Font size mismatch: "${textLine.slice(0, 30)}..." has size ${size}`);
break;
}
if (font !== "Times New Roman" && font !== "Garamond") {
status = "FAIL";
remarks.push(`Invalid font: "${textLine.slice(0, 30)}..." uses ${font}`);
break;
}
}
// Write results
formSheet.getRange(i + 1, statusCol + 1).setValue(status);
formSheet.getRange(i + 1, remarksCol + 1).setValue(remarks.join(" | "));
// Clean up: delete temporary Google Doc copy
DriveApp.getFileById(docId).setTrashed(true);
} catch (err) {
formSheet.getRange(i + 1, statusCol + 1).setValue("ERROR");
formSheet.getRange(i + 1, remarksCol + 1).setValue(err.toString());
}
}
}
// (rest of your functions: extractCGPAandSemester, , getPdfPageCount remain unchanged)
What you need to do to run this:
Enable Drive Advanced APIin Apps Script:Open your script editor > Click onServices(+ icon) > AddDrive API
Open your script editor > Click onServices(+ icon) > AddDrive API
Make sure your Google Sheet has columns named exactly:"Full Name""Upload Your CV""Validation Status" (will be created automatically if missing)"Remarks" (created automatically if missing)
"Full Name"
"Upload Your CV"
"Validation Status" (will be created automatically if missing)
"Remarks" (created automatically if missing)
Make sure CV file URLs are correct and accessibleby the script user.
RunvalidateCVs()manually or trigger on form submit(optional).
Enable Drive Advanced APIin Apps Script:
Open your script editor > Click onServices(+ icon) > AddDrive API
Open your script editor > Click onServices(+ icon) > AddDrive API
Make sure your Google Sheet has columns named exactly:
"Full Name"
"Upload Your CV"
"Validation Status" (will be created automatically if missing)
"Remarks" (created automatically if missing)
"Full Name"
"Upload Your CV"
"Validation Status" (will be created automatically if missing)
"Remarks" (created automatically if missing)
Make sure CV file URLs are correct and accessibleby the script user.
RunvalidateCVs()manually or trigger on form submit(optional).
If you want, I can help you create astep-by-step guideon setting up and running this, or help troubleshoot any errors you get. Just ask!