使用python生成excel表格
import datetime
import xlwt
workbook = xlwt.Workbook(encoding="utf-8")
sheet = workbook.add_sheet("统计报表", cell_overwrite_ok=True)
style_heading = xlwt.easyxf("""
font:
name 宋体,
colour_index black,
bold on,
height 0xD8;
align:
wrap off,
vert center,
horiz center;
pattern:
pattern solid,
fore-colour white;
borders:
left THIN,
right THIN,
top THIN,
bottom THIN;
"""
)
style_body = xlwt.easyxf("""
font:
name 宋体,
bold off,
height 0xD8;
align:
wrap on,
vert center,
horiz left;
borders:
left THIN,
right THIN,
top THIN,
bottom THIN;
"""
)
sheet.row(0).height_mismatch = True
sheet.row(0).height = 24 * 24
sheet.col(0).width = 1800
sheet.col(1).width = 7500
sheet.col(2).width = 7500
head_name = ["序号", "名称", "地址", ]
sheet.write_merge(0, 0, 0, 2, '标题',style_heading)
for i in range(len(head_name)):
sheet.write(1, i, str(head_name[i]), style_heading)
lnz_datas = ({"MC": "新能源有限公司", "DZ": "xx市xxx路xxxxx北门口南xxx号",},)
k = 2
for j in lnz_datas:
print(j)
sheet.write(k, 0, k, style_body)
sheet.write(k, 1, j["MC"], style_body)
sheet.write(k, 2, j["DZ"], style_body)
k += 1
now_time = datetime.datetime.now()
now_date = now_time.strftime("%Y%m%d%H%M%S")
excel_name = "统计报表" + str(now_date) + ".xls"
workbook.save('E:\\testdata\\' + excel_name)
最终结果: