简体   繁体   English

使用 xlsxwriter 作为引擎将 Pandas 样式转换为 Excel

[英]Pandas Style to Excel using xlsxwriter as engine

I am trying to return background color and font size but it only works when I return only one value, what's wrong in my code ?我正在尝试返回背景颜色和字体大小,但它仅在我只返回一个值时才有效,我的代码有什么问题?

this one wont work, I get this error :这个不行,我得到这个错误:

""" Format cells in Excel file and output to screen if on windows"""
color = 'red' if '>' in str(val) else 'lightgray'
font_size = '45px'
return f'font-size: {font_size} ,background-color: {color}'

but if I return only one it works either fontsize or color但如果我只返回一个,它可以使用 fontsize 或 color

""" Format cells in Excel file and output to screen if on windows"""
color = 'red' if '>' in str(val) else 'lightgray'
font_size = '45px'
return f'font-size: {font_size}'

Thanks for your help in advanced Dini感谢您对高级 Dini 的帮助

I had to use ;我不得不使用; instead of ,(comma) to pass as many paramters as I want.而不是 ,(comma) 来传递我想要的尽可能多的参数。

""" Format cells in Excel file and output to screen if on windows"""
color = 'red' if '>' in str(val) else 'lightgray'
font_size = '45px'
return f'font-size: {font_size} ; background-color: {color}'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM