1.9 supports setting style on a column / row, but it doesn't work at the moment for existing cells because excel assigns the column style to both the cell and the column, and openpyxl doesn't (yet).
from openpyxl import Workbook from openpyxl.styles import Style, Border wb = Workbook() ws = wb.active ws['A1'].value = 'Cell A1' ws['A2'].value = 'Cell A2' ws['B1'].value = 'Cell B1' default_style = Style(static=True) default_style.borders.left.border_style = Border.BORDER_THIN # This works for blank cells, but not for existing cells: ws._styles['A'] = default_style # Set style for Column A ws._styles = default_style # Set style for Row 1 # Maybe we can add something like: ws.setStyle('A', default_style) # Set for both column and existing cells
In this case a function like ws.setStyle could set the style to the column/row, and to all the cells that were in a column/row.
The only issue here, is that when adding a new cell:
If the style is modified, it should copy an existing column/row style, but this could be an expensive if added to worksheet.get_style(), so I suggest we ignore this.
When writing styles, if a cell style is not set, but a column / row style is, it should be written. This could happen by adding a column style and then adding a cell. This is less expensive.