您的位置:首页 > 其它

export excel

2016-07-07 18:34 537 查看
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()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息