我使用StyleFrame从 pandas 导出到 Excel。
默认情况下,单元格格式设置为“自动换行”和“缩小以适合”。 (如何)我可以更改这些设置吗?
API documentation描述了 utils 模块包含最广泛使用的样式元素值,并且只要 Excel 能够识别,就可以直接使用 utils 模块中不存在的值。
在这种情况下我需要为 Excel 指定什么?我如何/在哪里可以找到 Excel 的期望?非常感谢!
我尝试过的示例:
这段代码完美运行:
sf.apply_column_style(cols_to_style=['A'], styler_obj=Styler(bg_color=utils.colors.blue))
但我的问题是我不知道要更改什么来关闭文本换行和缩小以适合选项:
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'
最佳答案
从版本1.3开始,可以将wrap_text
和shrink_to_fit
直接传递给Styler
,例如no_wrap_text_style = Styler(wrap_text=False)
关于python - 使用 StyleFrame 从 pandas 到 Excel : how to disable the wrap text & shrink to fit?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47761063/