当用户按如下所示访问URL时,我试图返回xlsx文件,
from flask import Flask
from flask_restful import Api, Resource, reqparse
import pandas as pd
import numpy as np
import pymysql
import xlsxwriter
app = Flask(__name__)
api = Api(app)
class genGraph(Resource):
def get(self,day):
writer = pd.ExcelWriter('E:/report2.xlsx', engine='xlsxwriter')
i=1
sheet1 = pd.read_sql_query(query, connection)
columns = list(sheet1['areaName'].values.flatten())
sheet1.to_excel(writer,'Sheet%d'%(i), startrow=0, startcol=0)
workbook = writer.book
worksheet = writer.sheets['Sheet%d'%(i)]
col_length = len(sheet1.T.columns)
genGraph.format_worksheet(worksheet)
chart = workbook.add_chart({'type' : 'column'})
worksheet.insert_chart('C1', chart)
return 'Report Generated' #Here how to return that report2.xlsx file???
api.add_resource(genGraph, '/create/chart/<string:day>')
if __name__ == '__main__':
app.run(debug=True)
我要返回创建的文件,而不是返回字符串。
我如何有效地实现这一目标?