Cell Background Color (Openpyxl 2.0.4)

1,097 views
Skip to first unread message

Anil Tammineni

unread,
May 3, 2017, 4:32:42 AM5/3/17
to openpyxl-users
Hi,

I am trying to color background color of a cell using openpyxl 2.0.4 and Python 2.7.5
Code snippet attached and also pasted below.

Getting this error 
TypeError: expected <class 'openpyxl.styles.colors.Color'>

Can anyone help me in fixing this?

Thanks,
Anil

Here is the code snippet.
import openpyxl
from openpyxl import Workbook
from openpyxl.styles.fills import PatternFill
from openpyxl.styles.colors import Color

# writing contents
wb = Workbook()
ws = wb.active

ws.title = 'sum'

ws['A3'] = 100
print ws.cell('A3').value

yellow_pattern_fill = PatternFill(start_color= '00FFFF00', end_color= '00FFFF00', fill_type="solid")
ws.cell('A3').fill=yellow_pattern_fill

wb.save("ExcelCellColor_workbook.xlsx")



ExcelCellColor.py

Anil Tammineni

unread,
May 5, 2017, 5:39:25 AM5/5/17
to openpyx...@googlegroups.com
Hi,

Any thoughts on the fix?

Thanks,
Anil


--
You received this message because you are subscribed to the Google Groups "openpyxl-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openpyxl-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thomas Nygårds

unread,
May 5, 2017, 8:46:40 AM5/5/17
to openpyxl-users
The only difference I see when I compare against my code is that I use only FFFF00 instead of 00FFFF00:

yellow_pattern_fill = PatternFill(start_color= FFFF00', end_color= 'FFFF00', fill_type="solid")
ws.cell('
A3').fill=yellow_pattern_fill

But then you are also using a very old openpyxl verison. I am using 2.3.4 and that is also quite old...

Can you not upgrade?

Regards
Thomas
To unsubscribe from this group and stop receiving emails from it, send an email to openpyxl-user...@googlegroups.com.

Thomas Nygårds

unread,
May 8, 2017, 2:23:06 AM5/8/17
to openpyxl-users
I think the syntax was changed in 2.2 and you are using the new syntax.

Have a look at:
https://bitbucket.org/openpyxl/openpyxl/src/a07d28c65ea46f10e63537b15bfa6b8e91cf1768/openpyxl/styles/fills.py?at=2.0.4&fileviewer=file-view-default
for the syntax you should use.
Reply all
Reply to author
Forward
0 new messages