def write(cls, report_document: Document): """ Write the chapter 'Document history' with its table. Args: report_document: .docx file where the report is written. """ doc_history = cls(report_document) # add a heading to the chapter report_document.add_paragraph(doc_history.TITLE, doc_history.TITLE_STYLE) doc_history.add_table()
def write(report_document: Document): """ Add a table of content. The table of content will not appear at the first time. It has to be updated by pressing Ctrl + A, and then F9. Args: report_document: .docx file where the report is written. """ # add the heading of the table of content report_document.add_paragraph('Table of content', 'Table of content') # access to XML run element <w:r> paragraph = report_document.add_paragraph() run = paragraph.add_run() r = run._r # create new XML elements, set their attributes and add them to the run element # so that the table of content is considered as such and can be updated fldChar = OxmlElement('w:fldChar') fldChar.set(qn('w:fldCharType'), 'begin') r.append(fldChar) instrText = OxmlElement('w:instrText') instrText.set(qn('xml:space'), 'preserve') instrText.text = 'TOC \\o "1-2" \\h \\z \\u' # "1-2" correspond to heading levels r.append(instrText) fldChar2 = OxmlElement('w:fldChar') fldChar2.set(qn('w:fldCharType'), 'separate') fldChar3 = OxmlElement('w:t') fldChar3.text = 'Press "Ctrl + A" to select everything and then "F9" to update fields.' fldChar2.append(fldChar3) r.append(fldChar2) fldChar4 = OxmlElement('w:fldChar') fldChar4.set(qn('w:fldCharType'), 'end') r.append(fldChar4)
def write(cls, report_document: Document, text_input_document: Document, list_of_tables: List[str], parameters_dictionary: Dict[str, Union[str, int]] ): """ Write the chapter 'Participants’ characteristics' with its table if some participants were described. Args: report_document: .docx file where the report is written. text_input_document: .docx file where all inputs are written. list_of_tables: List of all table names. parameters_dictionary: Dictionary of all input parameters (key = parameter name, value = parameter value) """ participant_appendix = cls(report_document, text_input_document, list_of_tables, parameters_dictionary) if participant_appendix.described_rows[0] != 0: # add a heading to the chapter report_document.add_paragraph(participant_appendix.TITLE, participant_appendix.TITLE_STYLE) participant_appendix.add_table()
def _add_localisation_header(localisation, document: Document): """ Add a seperation for localisation :return: """ document.add_paragraph(localisation, style='Heading1')