Flask项目: Flask_Excel的使用

安装: pip install Flask_Excel

# -*- coding: utf-8 -*-

from flask import Flask, request, jsonify
import flask_excel as excel

app = Flask(__name__)


@app.route("/upload", methods=['GET', 'POST'])
def upload_file():
    if request.method == 'POST':
        return jsonify({"result": request.get_array(field_name='file')})
    return '''
    
    Upload an excel file
    

Excel file upload (csv, tsv, csvz, tsvz only)

'''
@app.route("/download", methods=['GET']) def download_file(): return excel.make_response_from_array([[1, 2], [3, 4]], "csv") @app.route("/export", methods=['GET']) def export_records(): return excel.make_response_from_array([[1, 2], [3, 4]], "csv", file_name="export_data") @app.route("/download_file_named_in_unicode", methods=['GET']) def download_file_named_in_unicode(): return excel.make_response_from_array([[1, 2], [3, 4]], "csv", file_name=u"中文文件名") # insert database related code here if __name__ == "__main__": excel.init_excel(app) app.run()

Flask项目: Flask_Excel的使用_第1张图片
在这里插入图片描述

你可能感兴趣的:(web)