赞
踩
代码
# 下载接口 import pandas as pd from flask import Flask, jsonify, request, redirect, render_template, send_from_directory @app.route("/downLoad", methods=["GET"]) def downLoad(): get_data = request.args.to_dict() id = get_data.get("id") details = InvoiceInformation.query.filter_by(fileId=id).all() data1 = [] for i in details: returnJson = {} data_json = json.loads(json.dumps(i, cls=JSONEncoder)) print(data_json['jsonStr']) json_str = eval(str(data_json['jsonStr'])) if "发票代码" in json_str: returnJson['发票代码'] = json_str['发票代码'] else: returnJson['是否通过'] = '未通过' if "发票号码" in json_str: returnJson['发票号码'] = json_str['发票号码'] else: returnJson['是否通过'] = '未通过' if "税后价格" in json_str: returnJson['税后价格'] = json_str['税后价格'] else: returnJson['是否通过'] = '未通过' if "开票日期" in json_str: returnJson['开票日期'] = json_str['开票日期'] else: returnJson['是否通过'] = '未通过' if '是否通过' in returnJson: pass else: returnJson['是否通过'] = ' 通过' if data_json['validation'] == 1: returnJson['真伪验证'] = '真' else: returnJson['真伪验证'] = '假' print(i['detailedData']) returnJson['详情'] = str(i['detailedData']) data1.append(returnJson) df = pd.read_excel("1.xlsx", header=None) ds = pd.DataFrame(data1) df = df.append(ds, ignore_index=True) fileNumber = str(time.time()).replace(".", '') df.to_excel(fileNumber+".xlsx", index=False, header=True) return send_from_directory(directory, path=directory, filename=fileNumber+".xlsx", as_attachment=True)
解读
data1 是我拼接的数据,如果没有什么意外情况,从数据库中查询出来,序列化一下,存储到list当中就可以直接追加进去
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。