Python EXCEL格式编辑函数StyleFrame使用大全

按照此方法,肯定不会报错,如果报错,请检查数据或者列名是否有问题(列名千万不要重复,否则肯定报错)

Styler(bg_color=None, bold=False, font=utils.fonts.arial, font_size=12, font_color=None, number_format=utils.number_formats.general, protection=False,
underline=None, border_type=utils.borders.thin, horizontal_alignment=utils.horizontal_alignments.center, vertical_alignment=utils.vertical_alignments.center,
wrap_text=True, shrink_to_fit=True, fill_pattern_type=utils.fill_pattern_types.solid, indent=0, comment_author=None, comment_text=None, text_rotation=0)
import pandas as pd
from styleframe import StyleFrame, Styler, utils
a=[1,2,3]
b=[4,5,6]
c=zip(a,b)
d=["时间",
   "电流"]
data=pd.DataFrame(c, columns=d)
#也可以这样
df = pd.read_excel('wendang6.xlsx')
print(type(df))
#先把转成StyleFrame样式
sf = StyleFrame(df)
#把所有的列
sf.apply_column_style(cols_to_style=column,
                      styler_obj=Styler(font="Times New Roman",font_color='red',shrink_to_fit=True,wrap_text=True),
                      style_header=False)
#设置行的样式
# sf.apply_style_by_indexes(indexes_to_style=sf[sf['时间']==1],
#                           # 要设置样式的行,sf[sf[‘col1’] = 20]表示设置col1列等于20的行
#                           # styler_obj=Styler(font="Times New Roman", font_color='green', shrink_to_fit=True,
#                           #                   wrap_text=True),
#                           # cols_to_style=d)
#                           cols_to_style=d,styler_obj=Styler(font_color="green"))
#设置好行高以后就存储
sf.set_column_width(columns = d,width=20)#这个函数是把表所有的列都设置成20
sf.set_column_width_dict(col_width_dict={"时间": 10, "电流": 10})#这个就是把某些列变成
sf.to_excel("235.xlsx").save()

至于其他的就看这个网址把

  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值