# 后台代码
@main.route('/report_export', methods=['GET']) | |
@login_required | |
def report_export(): | |
query_sets = Partner.query.limit(10).all() | |
column_names = ['partnerid', 'partnername'] | |
# pip install pyexcel-xlsx && pip install Flask-Excel | |
return flask_excel.make_response_from_query_sets(query_sets, column_names, file_type="xlsx", status=200, file_name='test') |
if __name__ == '__main__': | |
flask_excel.init_excel(app) | |
manager.run() |
# 前端
<a href="{{ url_for('main.report_export') }}">Export</a>
参考文档(里面有导入导出、下载等):
https://media.readthedocs.org/pdf/flask-excel/latest/flask-excel.pdf