Delete column after conditional formatting (formula) using xlsxwriter


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?




1 Answer
1



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', None, None, {'hidden': True})


worksheet.set_column('V', None, None, {'hidden': True})



See 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.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

how to run turtle graphics in Colaboratory

Export result set on Dbeaver to CSV