export excel

半世苍凉 提交于 2020-04-13 17:11:08

【今日推荐】:为什么一到面试就懵逼!>>>

You can install it via pip:

$ pip install Flask-Excel

or clone it and install it:

$ git clone http://github.com/pyexcel/Flask-Excel.git
$ cd Flask-Excel
$ python setup.py install

Installation of individual plugins , please refer to individual plugin page. For example, if you need xls file support, please install pyexcel-xls:

$ pip install pyexcel-xls

Setup

In your application, you must import it before using it:

from flask.ext import excel

or:

import flask.ext.excel

Quick start

A minimal application may look like this:

from flask import Flask, request, jsonify
from flask.ext import 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 '''
    <!doctype html>
    <title>Upload an excel file</title>
    <h1>Excel file upload (csv, tsv, csvz, tsvz only)</h1>
    <form action="" method=post enctype=multipart/form-data><p>
    <input type=file name=file><input type=submit value=Upload>
    </form>
    '''

@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")

# insert database related code here

if __name__ == "__main__":
    app.run()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!