Trouble with applying Styles in - OpenPyXL

一个人想着一个人 提交于 2019-12-05 14:31:26

As explained here, you should first create a Style object:

from openpyxl.styles import Style, Font

s = Style(font=Font(bold=True))

Then you can apply it to your cell like this:

_cell.style = s

This has changed since the accepted answer was given.

If you do what the accepted answer suggests, you will receive this warning: UserWarning: Use formatting objects such as font directly warn("Use formatting objects such as font directly")

The answer still works but the new solution would be to apply it to the cell directly, for example: worksheet.cell("C1").font = Font(bold=True)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!