python excel openpyxl 样式_python openpyxl 常用excel样式 脚本

-- coding: utf-8 --

from openpyxl import Workbook

from openpyxl.styles import Font

from openpyxl.styles import NamedStyle, Font, Border, Side,PatternFill

from openpyxl.styles import PatternFill, Border, Side, Alignment, Protection, Font

wb = Workbook()

ws = wb.active

ft = Font(name=u'微软雅黑',

size=11,

bold=False,

italic=False,

vertAlign=None,

underline='none',

strike=False,

color='FF000000')

fill = PatternFill(fill_type="solid",

start_color='FFEEFFFF',

end_color='FF001100')

边框可以选择的值为:'hair', 'medium', 'dashDot', 'dotted', 'mediumDashDot', 'dashed', 'mediumDashed', 'mediumDashDotDot', 'dashDotDot', 'slantDashDot', 'double', 'thick', 'thin']

diagonal 表示对角线

bd = Border(left=Side(border_style="thin",

color='FF001000'),

right=Side(border_style="thin",

color='FF110000'),

top=Side(border_style="thin",

color='FF110000'),

bottom=Side(border_style="thin",

color='FF110000'),

diagonal=Side(border_style=None,

color='FF000000'),

diagonal_direction=0,

outline=Side(border_style=None,

color='FF000000'),

vertical=Side(border_style=None,

color='FF000000'),

horizontal=Side(border_style=None,

color='FF110000')

)

alignment=Alignment(horizontal='general',

vertical='bottom',

text_rotation=0,

wrap_text=False,

shrink_to_fit=False,

indent=0)

number_format = 'General'

protection = Protection(locked=True,

hidden=False)

ws["B5"].font = ft

ws["B5"].fill =fill

ws["B5"].border = bd

ws["B5"].alignment = alignment

ws["B5"].number_format = number_format

ws["B5"].value ="zeke"

Save the file

wb.save("e:\sample.xlsx")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值