LoginSignup
1
0

More than 5 years have passed since last update.

XlsxWriterで文字列データに条件付き書式を適用させるときの注意

Last updated at Posted at 2018-04-15

最近個人的に、Pandasでこねくり回したデータをExcelで提供する機会が増えております。その際、条件付き書式で躓いたのでメモ。

思い込みで criteria に '=' を設定してみるとうまく動作しませんでした。これはダメな例。

bad_condition.py
worksheet.conditional_format('A1:A4', {'type':     'text',
                                       'criteria': '=',
                                       'value':    'foo',
                                       'format':   format1})

で、あらためてドキュメントを読んでみると、テキストデータに対して設定できるcriteriaは以下の4つのみとのことでした。

  • 'containing'
  • 'not containing'
  • 'begins with'
  • 'ends with'

なので、正しいサンプルコードは以下のようになります。

good_condition.py
worksheet.conditional_format('A1:A4', {'type':     'text',
                                       'criteria': 'containing',
                                       'value':    'foo',
                                       'format':   format1})

今後1のアップデートでどうなるかはわかりませんがメモ。


  1. この記事を書いている段階では1.03です。 

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0