我检查了另一条帖子并对其进行了更改,但是没有用。这是我的代码。
def writeTable(node,doc):
lines=node.find_all('tr')
clos=len(lines[0].find_all('td'))
table = doc.add_table(rows=0, cols=clos, style="Light List Accent 1")
i=0
for line in lines:
j=0
tds = line.find_all('td')
row_cells = table.add_row().cells
for item in tds:
if item.text is not None:
if item.contents[0].contents[0].name == "span":
styles = item.contents[0].contents[0].get('style').split(';')
for style in styles:
if style.__contains__('color'):
shading_elm_1 = parse_xml("<w:color %s w:val=\"%s\"/>"%(nsdecls('w'),style.replace('colr:#', '')))
row_cells[j]._tc.get_or_add_tcPr().append(shading_elm_1)
row_cells[j].text = item.text
j+=1
和来源:https://groups.google.com/forum/#!topic/python-docx/-c3OrRHA3qo