Как я должен установить цвет текста ячейки Python Docx - PullRequest
0 голосов
/ 29 августа 2018

Я проверил другой пост и внес в него изменения, но он не сработал. Это мой код.

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

...