python的excel处理之openpyxl

一、颜色处理

cell = sheet.cell(row, col)
font = Font(size=12, bold=False, name='Arial', color=colors.BLACK)
align = Alignment(horizontal='center', vertical='center')
thin = Side(border_style="thin", color="0000FF")
border = Border(left=thin, right=thin, top=thin, bottom=thin)

fill = PatternFill(start_color=colors.YELLOW, end_color=colors.YELLOW, fill_type="solid")
cell.fill = fill #背景色填充

cell.font = font #字体
cell.alignment = align  #位置
cell.border = border #边框

二、一些sheet追加,row、col、sheet合并单元格

1、追加

sheet.append(list)

2、获取row、col

sheet.max_row
sheet.max_column

3、合并单元格

sheet.merge_cells(start_row=1 , start_column=1, end_row=2, end_column=1)#此为合并列单元格,合并行,则处理行即可

三、打开保存excel

proDir = os.path.abspath('..')
wb = openpyxl.load_workbook(proDir + '\\'+localtime+'.xlsx')
wb.save(proDir + '\\'+localtime+'.xlsx')#可以重命名新文件,即保存新文件



posted @ 2019-08-26 14:48  流碟落  阅读(660)  评论(0编辑  收藏  举报