python docx set table cell background and text color

前端 未结 6 758
故里飘歌
故里飘歌 2021-01-12 20:51

I am using python 2.7 with docx and I would like to change the background and text color of cells in my table based on condition.

I could not find any usefull resour

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-12 21:33

    It looks like instead of using the cell.text = "Something" method you need to use the cell.add_paragraph("SomeText", a_style) with a defined style - probably one of:

    • ColorfulGrid
    • ColorfulGrid-Accent1
    • ColorfulGrid-Accent2
    • ColorfulGrid-Accent3
    • ColorfulGrid-Accent4
    • ColorfulGrid-Accent5
    • ColorfulGrid-Accent6

    Full list here.

    If you use the “default” template document - otherwise you will have to create your own.

提交回复
热议问题