Created
November 12, 2015 14:07
-
-
Save phucat/405cbed9610c88b88c45 to your computer and use it in GitHub Desktop.
excel export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# download xlsx writer here :XlsxWriter-0.7.7.tar.gz (md5) | |
#https://pypi.python.org/pypi/XlsxWriter#downloads | |
#extract and put to "lib" folder under root app directory | |
from cStringIO import StringIO | |
import xlsxwriter | |
out = StringIO() | |
wb = xlsxwriter.Workbook(out, {'in_memory': True}) | |
data = SampleModel.query().filter().fetch() | |
# x and y axis (row and column on excel file) | |
x = 1 | |
y = 0 | |
for item in data: | |
v = item.get('fieldname') | |
sheet.write(x, y, v) | |
wb.close() | |
out.seek(0) | |
# this will return excel in binary format | |
return out.read() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment