Reputation: 61
I'm using openpyxl 2.0.5 and python 3.4 and I'm simply trying to set the font color to a cell to red
from openpyxl import Workbook
from openpyxl.styles import Color, Font, Style, colors
wb = Workbook()
ws = wb.active
cell = 'A1'
ws[cell].styles = Style(font=Font(color=Color(colors.RED)))
Traceback (most recent call last): File "C:/Users/b-rosard/PycharmProjects/Test/test.py", line 12, in ws[cell].styles = Style(font=Font(color=Color(colors.RED)))
AttributeError: 'Cell' object has no attribute 'styles'
I was following the example here: http://openpyxl.readthedocs.org/en/latest/styles.html and I have no clue why I'm getting that error
Upvotes: 3
Views: 14869
Reputation: 374
This code worked for me. I am using python 3.x.
from openpyxl.styles import Color, Font, PatternFill
book = Workbook()
output = book.active
cell = output.cell(row = some value, column = some value)
cell.fill = cell.fill.copy(patternType = 'solid', fgColor = 'FFFFFF00')
'FFFFFF00' used for yellow
Upvotes: 0
Reputation: 61
Simple fix after looking at the attributes of Cell.
ws[cell].style = Style(font=Font(color=Color(colors.RED)))
Upvotes: 3