xlsxwriter模块add_format参数详解

本文详细介绍了使用Python的XlsxWriter库如何为Excel表格设置各种格式,包括数字、字体、对齐方式、填充和边框等。通过这些设置,可以轻松实现对Excel单元格样式的个性化定制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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			  # 上边框颜色

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值