赞
踩
1.首先设置mysql返回的结果为dict
self.cursor = self.conn.cursor(cursor=pymysql.cursors.DictCursor)
2.导入pandas
没安装先安装一下吧
pip install pandas
引入pandas
import pandas as pd
3.如何导出
json_info = mysqlhelper.get_all(sql)
df = pd.DataFrame(list(json_info))
file_path = "static/download_files/"+deploy_project_type+"_"+time.strftime("%Y%m%d", time.localtime())+".xlsx"
df.to_excel(file_path, encoding='utf-8', index=False)
这就完事了
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。