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()
来源:oschina
链接:https://my.oschina.net/u/1983678/blog/707931
