Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete column after conditional formatting (formula) using xlsxwriter

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?

like image 361
Hana Avatar asked Jun 30 '18 04:06

Hana


People also ask

How do I delete cells after conditional formatting?

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.

How do I delete a column in XlsxWriter?

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.

How do I use conditional formatting in pandas?

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 .


1 Answers

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.

like image 185
David Gaertner Avatar answered Sep 30 '22 14:09

David Gaertner