发布时间:2019-09-13 09:26:30编辑:auto阅读(1904)
每次给运营导数据的时候,如果不用工具的话,就是直接生成.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)
49296
48473
39187
36277
30689
27502
26494
21323
21173
19516
155°
351°
355°
453°
731°
519°
1184°
1170°
1145°
1142°