0
votes

i create an excel file with openpyxl in Flask app. i want to return the file into browser-window, just show, without edit.

@app.route('/excel_reports/cy_status_tn_print', methods=['GET'])
def cy_status_tn_print_xl():
    if request.method == 'GET':
        idx = request.args.get('idx', type=str)
        cont_no = request.args.get('in_cont_no', type=str)
        print_date = request.args.get('print_date', type=str)
        consignee = request.args.get('consignee', type=str)
        cargo_receipt = request.args.get('cargo_receipt', type=str)
        cargo_delivery = request.args.get('cargo_delivery', type=str)
        printer_no = request.args.get('printer_no', type=int)

    # answer
        p1, p2 = cy_status_tn_print.write_tn_print(
        print_date=print_date,
        consignee_id=consignee,
        cargo_delivery_id=cargo_delivery,
        cargo_receipt_id=cargo_receipt,
        idx=idx,
        in_cont_no=cont_no,
        printer_no=printer_no
    )
    # print('Answer: {}'.format(answer))
    return send_from_directory(directory=p1, filename=p2)

if i use send_from_directory() function, the file just downloaded in chrome. which function i should use to show excel in browser or it is impossible ?

1

1 Answers

0
votes

Try to set content-type of page

response.headers['Content-Type'] = 'application/vnd.ms-excel'