服务器保存excel地址
data = {}
dirpath = os.path.join(os.getcwd(), "ReportFiles")
if not dirpath:
os.makedirs(dirpath)
data["url"] = os.path.join(os.getcwd(), "report.xlsx")
data["json_data"] = report_json ##(excel报表数据)
接口代码
@app.route("/download/<directory>/<filename>", methods=['GET'])
def download_file(directory,filename):
"""
下载excel表主服务
:param directory: 文件夹
:param filename: 文件名字
:return:
"""
# 需要知道2个参数, 第1个参数是本地目录的path, 第2个参数是文件名(带扩展名)
directory_path = os.getcwd() + "/" + directory # 假设在当前目录
return send_from_directory(directory_path, filename, as_attachment=True)
@app.route("/api/download_report", methods=['POST'])
def download_report():
""
生成下载excel表的链接
:return:
"""
report = {}
report ["download_url"] = "http://服务器地址(IP或域名):端口" + str(data["url"].replace("\\","/"))
return jsonify(data))
网友评论