5

I've been fairly successful in conditionally formatting my excel file using pandas/excelwriter

However, I am having trouble create diverging colored databars, like the ones that can be create in excel:

enter image description here

I've tried to set a min and max color:

worksheet.conditional_format('G2:I80'{'type':'data_bar','min_color':'red','max_color':'green'})

But the result is this:

enter image description here

David Yang
  • 2,101
  • 13
  • 28
  • 46

2 Answers2

2

This is now possible in XlsxWriter version 1.0.4. See the databar Conditional Formatting Options.

For you case you could do something like this:

worksheet.conditional_format('G2:I80',
                             {'type': 'data_bar',
                              'min_color': 'red',
                              'max_color':'green',
                              'data_bar_2010': True,
                              })
jmcnamara
  • 38,196
  • 6
  • 90
  • 108
1

solved the problem here: https://github.com/jmcnamara/XlsxWriter/issues/501#issuecomment-378630647

There is attached worksheet.txt file that needs to be replaced
(rename file's extension from .txt to .py)

In order to use it just add: To add conditional_format just use:

worksheet.conditional_format("<RANGE>"),
     { 'guid': "<GUID>",
       'type': 'data_bar_bi_directional',
       'bar_color': '#8DB4E3',
       'min_type':'min',
       'max_type':'max'
      })

<RANGE> - replace with a range of cells that need to be extended with bi-directional data bars <GUID> - replace it with unique GUID

Denis Evseev
  • 1,660
  • 1
  • 18
  • 33