openpyxl day2 字体设置

import openpyxl
from openpyxl.styles import Font
from openpyxl.styles import colors

wb = openpyxl.Workbook()
ws = wb.active
ws.title = 'Font'
#默认字体 11pt,Calibri
italic24Font = Font(size=24,italic=True)  #设置字体对象
ws['B3'].font = italic24Font
ws['B3']='24pt Italic'
ws['A3']='24pt Italic'
boldRedFont = Font(name= 'Time New Roman',bold=True,color=colors.COLOR_INDEX[2])
ws['A1'].font = boldRedFont
ws['A1'] = 'Bold Red Time New Roman'
ws = wb.copy_worksheet(wb['Font'])  #表单对象
ws.title = 'Formula'   #公式
ws['A1'] = 200
ws['A2'] = 300
ws['A3'] = '=SUM(A1:A2)'
#setting row height and column width dimension 尺寸规模
ws = wb.create_sheet('dimensions')
ws['A1'] = 'Tall row'
ws.row_dimensions[1].height =70
ws['B2'] = 'Wide column'
ws.column_dimensions['B'].width =20
#Merging cells  合并单元格
ws = wb.create_sheet('merged')
ws.merge_cells('A1:D3')
ws['A1'] = 'Tweleve cells merged together'
ws.merge_cells('C5:D5')
ws['C5'] = 'Two merged cells'
#Unmerging cells 取消合并单元格
ws = wb.copy_worksheet(wb['merged'])
ws.title = 'unmerged'
ws.unmerge_cells('A1:D3')
ws.unmerge_cells('C5:D5')
wb.save('ss.xlsx')

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值