给那些想知道的人举个例子from docx import Document
from docx.shared import Inches
from docx.enum.table import WD_ALIGN_VERTICAL
from docx.enum.table import WD_TABLE_ALIGNMENT
from docx.enum.style import WD_STYLE
from docx.dml.color import ColorFormat
from docx.enum.dml import MSO_COLOR_TYPE
from docx.enum.text import WD_COLOR_INDEX
from docx.enum.text import WD_COLOR
from docx.shared import Pt
from docx.oxml.ns import nsdecls
from docx.oxml import parse_xml
document = Document()
document.add_heading('Document Title', 0)
table = document.add_table(1, 11)
table.style = 'Table Grid'
table.cell(0,1).merge(table.cell(0,4))
table.cell(0,6).merge(table.cell(0,7))
table.cell(0,9).merge(table.cell(0,10))
table.cell(0, 0).paragraphs[0].add_run("Name").bold = True
table.cell(0, 5).paragraphs[0].add_run("Offset").bold = True
table.cell(0, 1).paragraphs[0].add_run("5566")
table.cell(0, 6).paragraphs[0].add_run("never die")
table.cell(0, 9).paragraphs[0].add_run("1")
for i in range(11):
table.cell(0, i).paragraphs[0].alignment = WD_ALIGN_VERTICAL.CENTER
shading_elm = parse_xml(r''.format(nsdecls('w')))
#shading must create every time
table.cell(0, i)._tc.get_or_add_tcPr().append(shading_elm)
document.add_page_break()
document.save('demo2.docx')