pythonexcelpandasstyleframe

From pandas to Excel using StyleFrame: how to disable the wrap text & shrink to fit?


I use StyleFrame to export from pandas to Excel.

Cells are formatted to 'wrap text' and 'shrink to fit' by default. (How) can I change these settings?

The API documentation describes that the utils module contains the most widely used values for styling elements and that is possible to directly use a value that is not present in the utils module as long as Excel recognises it.

What do I need to specify for Excel in this case? Of how/where can I find out what Excel expects? Many thanks in advance!

Examples of what I have tried:

This code works perfect:

sf.apply_column_style(cols_to_style=['A'], styler_obj=Styler(bg_color=utils.colors.blue))

But my problem is that I do not know what to change to switch off the text wrapping and shrink to fit options:

sf.apply_column_style(cols_to_style=['A'], styler_obj=Styler(text_control=wrap_text.none))        
NameError: name 'wrap_text' is not defined

sf.apply_column_style(cols_to_style=['A'], styler_obj=Styler(text_control=utils.wrap_text.none)) 
AttributeError: module 'StyleFrame.utils' has no attribute 'wrap_text'

sf.apply_column_style(cols_to_style=['A'], styler_obj=Styler(utils.wrap_text.none)) 
AttributeError: module 'StyleFrame.utils' has no attribute 'wrap_text'

sf.apply_column_style(cols_to_style=['A'], styler_obj=Styler(wrap_text=False))        
TypeError: __init__() got an unexpected keyword argument 'wrap_text'

Solution

  • As of version 1.3 it is possible to pass wrap_text and shrink_to_fit directly to Styler, for example no_wrap_text_style = Styler(wrap_text=False)