Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Openpyxl - Apply Borders to Cells

I am hoping someone can help me as I have been unable to figure this one out for myself unfortunately.

I am trying to put a thin border around a cell using openpyxl 2.3.3 and python 3.4. I have the following code:

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'))

Oddly this is throwing the following error:

NameError: name 'Side' is not defined

I have looked at the official documentation here:

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

I have also looked at the following articles with no luck:

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

Apply Border To Range Of Cells Using Openpyxl

Is anyone able to help me out?

Thanks in advance,

Eamon

like image 874
Eamon Yates Avatar asked Jan 31 '16 18:01

Eamon Yates


1 Answers

You haven't imported the Side object.

from openpyxl.styles import Border, Side

like image 102
Charlie Clark Avatar answered Oct 03 '22 00:10

Charlie Clark