I am using pyopenxl to output some excel spreadsheets, I encountered a problem with font conditional formatting. I want to highlight the cells lesser than 0 with red color and here's what I've done:
from pyopenxl import formatting, styles
red_font = styles.Font(size=self.font_size, bold=bold, color=self.red_color_font)
red_fill = styles.PatternFill(start_color=self.red_color, end_color=self.red_color, fill_type='solid')
self.ws.conditional_formatting.add(
cell.coordinate,
formatting.CellIsRule(operator='lessThan', formula=['0'], fill=red_fill, font=red_font)
)
So I simply created styles for font and fill and applied them for my cell. The bad thing is that it doesn't work. As soon as I remove the font formatting from the CellIsRule()
everything goes back to normal and I'm having my cell filled with red. But the thing is that I need to change the color as well, does anyone has any idea what's wrong with my code? Or maybe with openpyxl?
red_color
andred_color_font
defined? Having red text with a red background would result in a red cell with no visible text. – Martin Evansself.red_color = 'ffc7ce'
andself.red_color_font = '9c0103'
. I should also add that they work perfectly well in any other situation, just not with conditional formatting :/ – Nhoropenpyxl
are you using?import openpyxl; print openpyxl.__version__
This seems to work fine for me on2.2.6
– Martin Evans2.2.5
and today switched to2.2.6
but with no success. Could you please paste your code? – Nhor