diff options
author | Artem Tarasov | 2015-05-07 18:05:57 +0300 |
---|---|---|
committer | Artem Tarasov | 2015-05-07 18:05:57 +0300 |
commit | cd9e120fa77a68f570d615a17071928d0c91aac2 (patch) | |
tree | ce2843f3ecfa0c38eb5149e32715cf29aaf870ac | |
parent | 53d8a8bff6418a203e3d2565aaeca4fcb5dc0752 (diff) | |
download | genenetwork2-cd9e120fa77a68f570d615a17071928d0c91aac2.tar.gz |
Excel export of trait data
-rw-r--r-- | misc/requirements.txt | 1 | ||||
-rwxr-xr-x | wqflask/wqflask/views.py | 19 |
2 files changed, 12 insertions, 8 deletions
diff --git a/misc/requirements.txt b/misc/requirements.txt index ec02a2c2..3487aa09 100644 --- a/misc/requirements.txt +++ b/misc/requirements.txt @@ -32,3 +32,4 @@ scipy==0.11.0 simplejson==3.0.7 wsgiref==0.1.2 yolk==0.4.3 +XlsxWriter=0.7.2 diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index abd8f05b..79c1c967 100755 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -5,6 +5,7 @@ import sys print("sys.path is:", sys.path) import csv +import xlsxwriter import StringIO # Todo: Use cStringIO? import gc @@ -186,7 +187,6 @@ def environments(): doc = docs.Docs("environments") return render_template("docs.html", **doc.__dict__) -# TODO @app.route('/export_trait_excel', methods=('POST',)) def export_trait_excel(): """Excel file consisting of the sample data from the trait data and analysis page""" @@ -197,15 +197,18 @@ def export_trait_excel(): print("sample_data - type: %s -- size: %s" % (type(sample_data), len(sample_data))) buff = StringIO.StringIO() - writer = csv.writer(buff) - for row in sample_data: - writer.writerow(row) - csv_data = buff.getvalue() + workbook = xlsxwriter.Workbook(buff, {'in_memory': True}) + worksheet = workbook.add_worksheet() + for i, row in enumerate(sample_data): + worksheet.write(i, 0, row[0]) + worksheet.write(i, 1, row[1]) + workbook.close() + excel_data = buff.getvalue() buff.close() - return Response(csv_data, - mimetype='text/csv', - headers={"Content-Disposition":"attachment;filename=test.csv"}) + return Response(excel_data, + mimetype='application/vnd.ms-excel', + headers={"Content-Disposition":"attachment;filename=test.xlsx"}) @app.route('/export_trait_csv', methods=('POST',)) def export_trait_csv(): |