Creating a student schedule Doc from a spreadsheet with students with apps script

127 views
Skip to first unread message

Geoff Scott

unread,
May 4, 2023, 6:34:38 PM5/4/23
to Google Apps Script Community
I am trying to create a Google Doc with a single page for each student that has their schedule. My spreadsheet has the students listed with class, period, time, teacher, and room #. I keep getting the same error
"Exception: The parameters (number,number) don't match the method signature for SpreadsheetApp.Range.getValue."
When I try to run the apps script.
Here's the link to the spreadsheet:

Here is the apps script I'm using
function createStudentDocs() {
// Get the spreadsheet.
var spreadsheet = SpreadsheetApp.openById("1104QnTUhDs-gmKVgWfk1wrYVjTc6XmgCOPJe9q7JLbs");
// Get the range of cells that contains the student information.
var studentDataRange = spreadsheet.getRange("A1:F100");

// Create a new Google Doc.
var doc = DocumentApp.create("Student Information");

// Create a new array to store the unique student names.
var uniqueStudentNames = [];

// Iterate over the rows in the student data range.
for (var i = 1; i <= studentDataRange.getNumRows(); i++) {
// Get the student's name.
var studentName = studentDataRange.getValue(i, 0);

// If the student name is not already in the array, add it to the array.
if (uniqueStudentNames.indexOf(studentName) === -1) {
uniqueStudentNames.push(studentName);
}
}

// Iterate over the unique student names.
for (var studentName of uniqueStudentNames) {
// Get the student's classes.
var classes = [
studentDataRange.getValue(studentDataRange.findRow(studentName), 1),
studentDataRange.getValue(studentDataRange.findRow(studentName), 2),
studentDataRange.getValue(studentDataRange.findRow(studentName), 3),
studentDataRange.getValue(studentDataRange.findRow(studentName), 4),
studentDataRange.getValue(studentDataRange.findRow(studentName), 5)
];

// Create a new page for the student.
var page = doc.appendPage(studentName);

// Add the student's name to the page header.
page.setHeader("Student Name: " + studentName);

// Add the student's classes to the page body.
for (var j = 0; j < classes.length; j++) {
var classInfo = classes[j];
page.appendParagraph(classInfo);
}
}

// Save the document.
doc.save();
}

I just would like the doc to list the student's name and include their classes in time or period order with the room # and teacher and time.
Thank you in advance.


CBMServices Web

unread,
May 4, 2023, 9:33:42 PM5/4/23
to google-apps-sc...@googlegroups.com
The method getValue is usually called with no parameters.

What you need to set is the range. But you defined the range already in your variable studentDataRange.

So this statement is incorrect and would need to be changed.

studentDataRange.getValue(i, 0);



What I would suggest is to grab all the data from spreadsheet then iterate over it in your loop.

Use this:

var sheetData = spreadsheet.getDataRange(),getValues();

Then poke at the sheetData as you need to to create the doc. SheetData is going to be a 2 dimensional array with first index as row, second one as column.

So sheetData[0][0]  represents value in cell row 1, col 1.

Hope that helps.




--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/fa0151c6-b2be-4718-9a6b-1af7d5d1770dn%40googlegroups.com.

Geoff Scott

unread,
May 5, 2023, 10:05:29 AM5/5/23
to Google Apps Script Community
Thank you, George, but I didn't write this script. I actually used BARD to help write it, so I am not very familiar with the language. 
Would you mind going a little more in-depth? I can figure it out with a bit more help, I think.
Thanks

Geoff Scott

unread,
May 5, 2023, 10:07:04 AM5/5/23
to Google Apps Script Community
If you have a better way to create the final schedule product, I'll take suggestions.

Brian Pugh

unread,
May 5, 2023, 10:16:55 AM5/5/23
to google-apps-sc...@googlegroups.com
I used to do this by using AutoCrat for hundreds of timetables. It worked perfectly.




















Brian Pugh, IT/Educational Technologies



Associated Hebrew Schools | Danilack Middle School

p: 416.494.7666, | e: bp...@ahschools.com

w: www.associatedhebrewschools.com

252 Finch Ave W., Toronto, ON M2R 1M9


facebook.png twitter.png instagram.png 


This email is confidential and is intended for the above-named recipient(s) only. If you are not the intended recipient, please delete this email from your system. Any unauthorized use or disclosure of this email is prohibited.




CBMServices Web

unread,
May 5, 2023, 11:59:39 AM5/5/23
to google-apps-sc...@googlegroups.com
Hi Geoff,

 I would be happy to help.

Provide me with editor access to the spreadsheet and will make the changes for you.


Geoff Scott

unread,
May 5, 2023, 4:09:22 PM5/5/23
to Google Apps Script Community
Brian Thank you, I will definitely look into that one. It does look the way I want it to.

Geoff Scott

unread,
May 5, 2023, 4:09:57 PM5/5/23
to Google Apps Script Community
@george, I changed the editor settings, try now. 

On Friday, May 5, 2023 at 10:59:39 AM UTC-5 George wrote:

Mr. Geoff Scott

unread,
May 6, 2023, 4:31:59 PM5/6/23
to Google Apps Script Community
All done. Thank you all for your help. 

CBMServices Web

unread,
May 6, 2023, 4:47:06 PM5/6/23
to google-apps-sc...@googlegroups.com

Sunil Bhatt

unread,
May 7, 2023, 2:22:45 AM5/7/23
to Google Apps Script Community
Hello Folk,
Greetings!
I am reaching out to seek a solution regarding data automation through Apps Script. Specifically, I have a collection of CSV files stored in my Google Drive, with a new file being generated each day. My objective is to extract data from these files and import it into my Google Sheet. It is worth noting that the format remains consistent across all the files.

Will the below code work in this case:
function importDataFromDrive() { var folderId = 'YOUR_FOLDER_ID'; // Replace with the ID of your Google Drive folder var sheetId = 'YOUR_SHEET_ID'; // Replace with the ID of your Google Sheet var folder = DriveApp.getFolderById(folderId); var files = folder.getFilesByType(MimeType.CSV); var sheet = SpreadsheetApp.openById(sheetId); var targetSheet = sheet.getActiveSheet(); // You can modify this to target a specific sheet while (files.hasNext()) { var file = files.next(); var csvData = file.getBlob().getDataAsString(); var csv = Utilities.parseCsv(csvData); targetSheet.getRange(targetSheet.getLastRow() + 1, 1, csv.length, csv[0].length).setValues(csv); } }

Sunil Bhatt

unread,
May 7, 2023, 2:34:58 AM5/7/23
to Google Apps Script Community
Screenshot 2023-05-07 at 12.04.30 PM.png
Reply all
Reply to author
Forward
0 new messages