# 获取所有sheet页
wb.sheetnames
# 根据名字获取sheet
wb['name']
# 创建sheet
wb.create_sheet(title='name',index = 1)
设置边框/字体/对齐方式/背景
from openpyxl.styles import Border, Side, Alignment, Font, Color, PatternFill
from openpyxl.utils import get_column_letter, column_index_from_string
# 字体
cell.font = Font(name=u'微软雅黑', size=10, bold=True, italic=True) # 字体,大小,加粗,斜体
# 边框
cell.border = Border(left=Side(border_style='thin', color='00000000'),
right=Side(border_style='thin', color='00000000'),
top=Side(border_style='thin', color='00000000'),
bottom=Side(border_style='thin', color='00000000'))
# 对齐方式
cell.alignment = Alignment(horizontal='center', vertical='center', wrap_text=True) # 左右居中,上下居中,自动换行
# 合并
ws.merge_cells('J1:Q1')
ws.merge_cells(strat_row,start_column,end_row,end_column)
# 获取合并的位置
ws.merged_cells(1,1). # 左上角为第一行第一列 返回(1,1,2,2) 即开始行列,结束行列
# 取消合并
ws.unmerge_cells(1,1). # 左上角为第一行第一列
# 设置行高 列宽
ws.row_dimensions[1].height = 58
ws.column_dimensions['A'].wight = 150 # 列宽
# 背景颜色
cell.fill = PatternFill('solid', fgColor='B8BBDE')
# 根据列的数字返回字母
print(get_column_letter(2)) # B
# 根据字母返回列的数字
print(column_index_from_string('D')) # 4