#1.第一步导入相应的模块
import xlwt
from xlwt import *
#2.第二步创建excel表格
workbook = xlwt.Workbook()
sheet = workbook.add_sheet('My Sheet')
#3.第三步定义表格样式
sheet.col(h+0).width = 128 * 20
title_style = xlwt.XFStyle()
title_style.alignment.horz = xlwt.Alignment.HORZ_CENTER
title_style.font.bold = True
title_style.font.height = 20 * 18
style = xlwt.easyxf('align: wrap on')
center_style = xlwt.XFStyle()
center_style.alignment.horz = xlwt.Alignment.HORZ_CENTER
center_style.alignment.vert = xlwt.Alignment.VERT_CENTER
#4.第四步填写内容
sheet.write_merge(h+0, h+0, v+0, v+15, u'工作月报', title_style)
sheet.write(h+1, v+4, u'工号', center_style)
sheet.write_merge(h+1, h+1, v+5, v+7, data0[i]["user_id"], center_style)
sheet.write(h+1, v+8, u'姓名', center_style)
sheet.write_merge(h+1, h+1, v+9, v+11, data0[i]["name"], center_style)
sheet.write(h+1, v+12, u'填写日期', center_style)
sheet.write_merge(h+1, h+1, v+13, v+15, t, center_style)
#5.第五步保存
workbook.save('/home/dingding/ding_month_1/‘’)
python操作Excel格式与下载
最新推荐文章于 2024-06-21 14:50:36 发布