发布时间:2019-09-13 09:26:30编辑:auto阅读(2071)
每次给运营导数据的时候,如果不用工具的话,就是直接生成.csv格式的文件,这样的文件不支持'sheet',每次还有手工进行,相当的不科学,今天试试Python生成excel文件。
写的糙了点,但是这是一个很好的开始!
改进版本:数据库内容到EXCEL
#!/usr/bin/env python
import xlwt
import MySQLdb
wbk=xlwt.Workbook()
sheet=wbk.add_sheet('sheet 1')
sheet.write(0,0,'company')
sheet.write(0,1,'city')
row=1
conn=MySQLdb.connect(host='XXX',user='XXX',passwd='XXX',db='gh')
cursor=conn.cursor()
cursor.execute('select * from customers')
for com,city in cursor.fetchall():
sheet.write(row,0,com)
sheet.write(row,1,city)
row+=1
wbk.save(city.xls)
cursor.close()
conn.commit()
conn.close()
参考地址:http://scienceoss.com/write-excel-files-with-python-using-xlwt/
上一篇: Python [4] Django的安装
下一篇: Python第五周 学习笔记(2)
51188
50598
41223
38042
32507
29412
28274
23125
23089
21420
1470°
2190°
1815°
1746°
2056°
1808°
2489°
4179°
4044°
2886°