给想知道的人举个例子吧from docx导入文档
from docx.shared import Inches
from docx.enum.tableimportwd _ align _ vertical
from docx.enum.tableimportwd _ table _ alignment
from docx.enum.styleimportwd _ style
from docx.dml.color import殷勤的大门/pfromdocx.enum.dmlimportmso _ color _ type
from docx.enum.textimportwd _ color _ index
from docx.enum.textimportwd _ color
from docx.shared import Pt
from docx.oxml.ns import nsdecls
from docx.oxml import parse_xml
文档=文档(
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).add_run ) ' neverdie ' () ) ) ) ) ) ) ) )。
table.cell (0,9 ).paragraphs[0].add_run ) '1) ) ) ) ) ) ) )。
forIinrange(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 ) () ) ) )。
文档. add _ page _ break (
文档. save (demo2. docx ) )。