I'm creating report cards for a school. Each teacher submits a spreadsheet with the names, grade, letter grade and a comment for each student. Such as, John, 85, B, Good job!. In addition, there are spreadsheets from the homeroom teacher and advisor which contain comments, roughly a short paragraph, and citizenship grades. All this information is collected in a panda dataframe and then turned into a list of dictionaries that the .merge_templates() function will use.
The list 'all_data' contains eight dictionaries, one for each student. Each dictionary has 42 keys. Twelve of the 42 are comments ranging from one or two sentences to a paragraph.
The mailmerge is performed with this code:
template = "Grade 11 Template.docx"
newdoc = "data/output/Grade 11 Report.docx"
document = MailMerge(template)
document.merge_templates(all_data, separator="page_break")
document.write(newdoc)
Here is the problem: On the last report card, the first MergeField is a comment which does not get read into the template completely. It stops mid-sentence. I printed the dictionary and it has the entire comment. The previous seven report cards are all fine. The rest of the last report card is also fine. It just drops part of that first comment for the last student.
I tried going back to the original spreadsheet and resaving the information. Same result. When I tried shortening 'all_data' to just two students the problem goes away. This makes me think I'm hitting some sort of character limit. Eight students isn't that many students though.
Is it better to write one report card at a time? 'Grade 11 Report.docx' for all eight students is only 32 pages long. It doesn't seem like it should be that huge of a file to create a problem.
Any insights are greatly appreciated.
I have faced time issue,
docx-mailmerge
has taken nearly 10 minutes to merge the 20 fields. I figured out it is in package itself, Alternatively useddocx-mailmerge2
it solved performance issue. it 10X faster thandocx-mailmerge