python之excel导出
excel操作导出excelManager.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import xlwt
def generate_excel(rows,titleRow=[],filename='1.xls',sheetName="基本信息"):
wbk = xlwt.Workbook(encoding='utf-8')
sheet = wbk.add_sheet(sheetname=sheetName)
i = 0;
titleRow_len =len(titleRow);
if titleRow_len <= 0:
for key in rows[0]:
titleRow.append({key:key});
for col in range(titleRow_len):
sheet.write(i,col,titleRow[col].values()[0])
for row in rows:
i=i+1;
for col in range(titleRow_len):
value = row[titleRow[col].keys()[0]]
if value is None:
value = '';
sheet.write(i, col,value )
wbk.save(unicode(filename, 'utf-8'));
print "生成excel文件:",filename 相关推荐
zhangchaoming 2020-05-17
ipqtjmqj 2020-04-21
Yyqingmofeige 2020-03-23
jzlixiao 2020-03-06
sdwylry 2020-02-20
chichichi0 2020-01-07
云之高水之远 2020-01-03
糊一笑 2020-01-02
huakai 2019-12-23
tvk 2019-12-19
waitwolf 2019-12-07
torrent0 2019-11-17
zxznsjdsj 2019-11-04
liusarazhang 2019-10-31
86427019 2019-10-29
laxexue 2019-09-06
yuelcay 2019-09-06