from xlwt import *
import os
# 导出数据
@sqb.route('/output_data', methods=['GET', 'POST'])
def output_data():
try:
#elders 是从数据库查询到的数据,这个自己写
#"""
导出excel表格
"""
if elders: # 创建工作薄
ws=Workbook(encoding='utf-8')
# ws = Workbook(encoding='utf-8')
w=ws.add_sheet(u"老人信息")
w.write(0, 0, u"姓名")
w.write(0, 3, u"年龄")
# 写入数据
excel_row = 1
for elder in elders:
w.write(excel_row, 0, elder['name'])
w.write(excel_row, 1, elder['age'])
excel_row += 1
#设置单元格格式
w.col(2).width = 400 * 20
w.col(4).width = 300 * 20
filepath = os.path.join(sqb.static_folder, 'upload/&
Python 导出数据至Excel
最新推荐文章于 2023-03-17 23:43:05 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)