I am trying to automatically merge columns of tables using docxtpl on python.
My tables are in the following form:
context = {
'tbl_contents': [
{'label': '1', 'cols': ['A','A','B']},
{'label': '2', 'cols': ['C', 'C', 'B'},
{'label': '3', 'cols': ['A', 'E', 'D']},
]
}
The table is then dynamically filled, iterating on lines
I would like to be able to horizontally merge all cells containing the same character, to turn this:
+---+---+---+
1 | A | A | B |
+---+---+---+
2 | C | C | B |
+---+---+---+
3 | A | E | D |
+---+---+---+
into this:
+---+---+---+
1 | A A | B |
+-------+---+
2 | C C | B |
+---+---+---+
3 | A | E | D |
+---+---+---+
I saw that on Github there is a script that vertically merges cells of a docx-tpl document, but it does not seem to do it horizontally.
I also saw in this post that with python-docx there seems to be a way to merge cells.
Does anybody have an answer to this problem?
user25169060 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.