Setting styles in Openpyxl

后端 未结 7 899
遇见更好的自我
遇见更好的自我 2020-12-01 03:17

I need advice on setting styles in Openpyxl.

I see that the NumberFormat of a cell can be set, but I also require setting of font colors and attributes (bold etc). T

相关标签:
7条回答
  • 2020-12-01 04:17

    This seems like a feature that has changed a few times. I am using openpyxl 2.5.0, and I was able to set the strike-through option this way:

    new_font = copy(cell.font)
    new_font.strike = True
    cell.font = new_font
    

    It seems like earlier versions (1.9 to 2.4?) had a copy method on the font that is now deprecated and raises a warning:

    cell.font = cell.font.copy(strike=True)
    

    Versions up to 1.8 had mutable fonts, so you could just do this:

    cell.font.strike=True
    

    That now raises an error.

    0 讨论(0)
提交回复
热议问题