Openpyxl - 将边框应用于单元格

Openpyxl - Apply Borders to Cells

我希望有人能帮助我,因为不幸的是我一直无法自己解决这个问题。

我正在尝试使用 openpyxl 2.3.3 和 python 3.4 在单元格周围放置细边框。我有以下代码:

from openpyxl.styles import Border

ws.cell('A1').border = Border(top = Side(border_style='thin', color='FF000000'),    
                              right = Side(border_style='thin', color='FF000000'), 
                              bottom = Side(border_style='thin', color='FF000000'),
                              left = Side(border_style='thin', color='FF000000'))

奇怪的是,这引发了以下错误:

NameError: name 'Side' is not defined

我在这里查看了官方文档:

http://openpyxl.readthedocs.org/en/2.4/styles.html http://openpyxl.readthedocs.org/en/2.4/_modules/openpyxl/styles/borders.html

我也看过以下文章,但没有运气:

https://bitbucket.org/openpyxl/openpyxl/issues/365/styling-merged-cells-isnt-working

Applying borders to a cell in OpenPyxl

Apply borders to all cells in a range with openpyxl

有人能帮我吗?

提前致谢,

埃蒙

您还没有导入 Side 对象。

from openpyxl.styles import Border, Side