I have a column (column V) that I used to conditionally format another column (column U) using engine xlsxwriter.
So I have this:
# Light yellow fill with dark yellow text.
format1 = workbook.add_format({'bg_color': '#FFEB9C'})
# Light red fill with dark red text.
format2 = workbook.add_format({'bg_color': '#FFC7CE',
'font_color': '#9C0006'})
worksheet.conditional_format('U2:U1000', {'type': 'formula',
'criteria': '=V2>25',
'format': format1})
worksheet.conditional_format('U2:U1000', {'type': 'formula',
'criteria': '=V2<-20',
'format': format2})
So now after highlighting column U with conditional formatting, I want to delete column V (yet keep the highlighting intact). Is there a way to do this in xlsxwriter?
To remove conditional formatting from specific cells, select the cells, click the Quick Analysis button, and click Clear Format. To remove all conditional formatting from the entire worksheet,click the Conditional Formatting button on the HOME tab, point to Clear Rules, and click Clear Rules from Entire Sheet.
You cannot delete a column with XlsxWriter. The best option is to structure your application so it doesn't write data to the column in the first place.
Conditional cell highlighting. One way to conditionally format your Pandas DataFrame is to highlight cells which meet certain conditions. To do so, we can write a simple function and pass that function into the Styler object using . apply() or .
Because it's a conditional format using a formula, deleting the referenced column will remove what's being referenced and "break" the formula.
You could hide column V instead with the following code.
worksheet.set_column('V:V', None, None, {'hidden': True})
If you need to hide single column then you need to set it like 'V:V'
http://xlsxwriter.readthedocs.io/example_hide_row_col.html
If we were talking about formulas for numbers, I would copy then "paste values" to remove the formulas. As far as I know, there isn't a way in Excel to copy and paste formats without also copying the conditional formula.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With