xlsxwriter模块add_format参数说明

workbook.add_format([格式字典])

# 数字
num_format = 'General'    # 数字格式
 
# 字体
font_name = 'Arial'       # 字体
font_size = 11            # 字号
font_color = 0x0          # 颜色
bold = True               # 加粗
italic = True             # 斜体
underline = 0             # 下划线,0:无;1:单下划线;2:双下划线;……
font_strikeout = True     # 删除线
font_script = 0           # 上下标,0:无;1:上标;2:下标
font_outline = True       # 轮廓
font_shadow = True        # 阴影
 
# 保护
hidden = False            # 隐藏
locked = True             # 锁定
 
# 对齐
align = 'left'            # 水平对齐 'left'|'centre'|'right'|'fill'|'justify'|'centre_across'|'distributed'|'justify_distributed'
valign = 'vcentre'        # 垂直对齐 'top'|'vcentre'|'bottom'|'vjustify'|'vdistributed'
text_wrap = True          # 自动换行
rotation = 0              # 旋转
indent = 1                  # 缩进
shrink = True              # 缩小字体填充
 
# 填充
pattern = 1                  # 图案样式
fg_color = 0              # 前景色
bg_color = 0              # 背景色
 
# 边框
border = 0                  # 边框,0:无边框;1:外边框;……
border_color = 0x0          # 边框颜色
diag_border = 0
diag_color = 0x0
diag_type = 0
bottom = 0                  # 底边框
bottom_color = 0x0          # 底边框颜色
left = 0                  # 左边框
left_color = 0x0          # 左边框颜色
right = 0                  # 右边框
right_color = 0x0          # 右边框颜色
top = 0                      # 上边框
top_color = 0x0              # 上边框颜色具体 

官网地址:https://xlsxwriter.readthedocs.io/format.html

请注意,xlsxwriter在写入Excel文件时不支持直接修改已存在的单元格样式,因此您需要在创建单元格时指定样式。

比如:我需要修改C4单元格的内容为自动换行,那么必须使用write方法,并且加上format参数即可:

text_format = writer.book.add_format({'align': 'center', 'border': 1, 'text_wrap': True, 'bold': True})
worksheet.write('C4', '这是一个长标题', text_format)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lytcreate.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值