0

Consider there are two tables in a MS docx file. First Table with X rows and Y columns and second table with M rows and N columns in the same MS docxfile. Now i want to copy complete second table along with its contents to one of cell (say cell (X,Y)) of first table in python. Example of table shown below:

First Table with 2 columns 5 rows Second Table with 3 columns 4 rows

Now i want to copy second table full content with formatting into last cell of the first table. Final result after copy should look like below:

Result table

How do we achieve this in python ?

1 Answers1

0

From PyPi: Merge table rows. In your template, add a MergeField to the row you would like to designate as template. Supply the name of this MergeField as anchor parameter. The second parameter contains the rows with key-value pairs for the MergeField replacements.

document.merge_rows('col1',
                    [{'col1': 'Row 1, Column 1', 'col2': 'Row 1 Column 1'},
                     {'col1': 'Row 2, Column 1', 'col2': 'Row 2 Column 1'},
                     {'col1': 'Row 3, Column 1', 'col2': 'Row 3 Column 1'}])
j_rothmans
  • 31
  • 5