python mysqldb 读取数据存储到excel中
2015-04-17 16:27
260 查看
from pyExcelerator import * import MySQLdb import time def get_data_from_mysql(host,user,passwd,db,sql): #连接 conn=MySQLdb.connect(host,user,passwd,db,charset="utf8") cur=conn.cursor() #查询 n=cur.execute(sql) content=[] for row in cur.fetchall(): "返回整行数据tuple类型" content.append(row) return n,content aa=get_data_from_mysql(host="",user="",passwd="",db='db1',sql="") #返回结果行数,以及具体的数据信息 co=aa[1] #具体数据元组a[1][0] a[1][1]..... w = Workbook() #创建一个工作簿 ws = w.add_sheet('Hey, Hades') #创建一个工作表 for j in range(0,10): for i in range(0,len(aa[1][0])): ws.write(j,i,u'%s' %(co[j][i])) w.save("d://basedata//xxoo.xls") #保存
相关文章推荐
- 使用Python3 xlrd pymysql 实现读取Excel数据读取以及mysql存储
- python读取Excel数据
- python 读取excel数据
- 用Python读取excel中的数据
- python读取excel表格数据
- Python存储和读取数据
- python-把excel里面的数据存储到矩阵里面
- python中删除列表中的空元素以及如何读取excel中的数据
- java读取数据库中的数据并存储到excel中去
- Python读取Excel数据
- python读取excel数据
- python 对excel中数据的读取
- 怎么从excel中读取数据_python
- python初学者学习笔记(三)读取excel表格数据
- Delphi中使用python脚本读取Excel数据
- python读取excel中的数据
- [Python]网络数据采集概述(2)—存储数据及读取文档
- Python导出数据到Excel可读取的CSV文件的方法
- Python 文本挖掘:数据存储和读取
- python 读取excel数据到mysql