python - 使用 StyleFrame 从 pandas 到 Excel : how to disable the wrap text & shrink to fit?

标签 python excel pandas styleframe

我使用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_textshr​​ink_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/

相关文章:

python - 如何对 numpy.ndarray 对象的子集应用函数

java - poi 在 eclipse 中工作但不在 tomcat 中工作

python - 嵌套的 If-else pandas 数据框

python - 在 Python 中使用循环创建数组的交替列表

python - Python 中的列表比较

python - 从 IPython notebook 运行 MRJob

vba - 删除 Excel 中的图表

java - 在 java 中使用 MS Excel 查找表或任何类似的解决方案

python - 通过仅跳过空白行来读取 excel 文件 (pd.read_excel())

python - Pandas Dataframe Groupby 连接字符串,同时保留字符串的顺序