Cell spanning multiple columns in table using python-docx

不打扰是莪最后的温柔 提交于 2019-12-06 03:03:18

I added a merge_cells() function to the row class of python-docx, that can merge any cells on a single row. I'm hoping it will get included in python-docx. In the meantime, you can grab it from my github "merge_cells_feature" python-docx branch.

I'm copying the example I wrote on the pull request here for reference:

from docx import Document

doc = Document()
table = doc.add_table(6,6)
header_row = table.rows[0]
header_row.merge_cells()

# args can also be passed to merge_cells(mergeStart, mergeStop) in order to 
# implement any kind of merge on the same row, such as:
table.rows[1].merge_cells(0,3)  # This will merge the cells indexed from 0 to 2.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!