talkingtoaj / unique-exams

Create a unique exam for every student
MIT License
0 stars 0 forks source link

Improving copying of Word docx elements #1

Open talkingtoaj opened 1 year ago

talkingtoaj commented 1 year ago

The problem

We're using the python-docx package, which seems to be the best developed python package for ingesting and exporting docx files out there, but it is woefully lacking in some basics.

Currently our program will copy paragraphs and their formatting well, but the following are lost between being ingested from the template to the unique exams:

Desired solution

Some functions that will be called by load_in_template() and add_paragraph() which will ensure more of the Word elements are preserved.

talkingtoaj commented 1 year ago

Tables

From what I have been able to tell by pausing execution in the debugger, tables are not saved within paragraphs, but instead exist in document._body.tables

Tables are inserted via document._element._insert_tbl(tbl)

Existing tables can be inspected via [Table(tbl, self) for tbl in document._element.tbl_lst]

Styles

I believe paragraph spacing is possibly being lost because styles are not copying over.