Skip to content

Commit ae92af2

Browse files
authored
[Comp-787] IR Docx change max table width inside requirements (#736)
1 parent bd88d75 commit ae92af2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

compliance-api/src/compliance_api/services/inspection_record/inspection_record_doc_generator.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,26 @@ def add_html_table_to_container(container, table_element):
327327
# Create docx table
328328
docx_table = container.add_table(rows=len(rows), cols=max_cols)
329329
docx_table.style = 'Table Grid'
330+
docx_table.autofit = False
331+
332+
# Set table width
333+
if hasattr(container, 'width'):
334+
parent_width_emu = container.width if isinstance(container.width, int) else container.width.emu
335+
table_width_emu = parent_width_emu - Inches(0.16).emu
336+
else:
337+
table_width_emu = Inches(7.09).emu
338+
339+
# Apply width at XML level
340+
tbl = docx_table._element
341+
tblPr = tbl.tblPr
342+
if tblPr is None:
343+
tblPr = OxmlElement('w:tblPr')
344+
tbl.insert(0, tblPr)
345+
346+
tblW = OxmlElement('w:tblW')
347+
tblW.set(qn('w:w'), str(int(table_width_emu / 635)))
348+
tblW.set(qn('w:type'), 'dxa')
349+
tblPr.append(tblW)
330350

331351
# Populate table
332352
for row_idx, tr in enumerate(rows):

0 commit comments

Comments
 (0)