In controller, forxample default.py:
def export_csv():
animals = db().select(db.purchase_type.ALL)
fname='hello.csv'
return dict(animals1=animals, fname=fname)
In view: view/default folder:
make flie export_csv.csv:
{{
import cStringIO
stream=cStringIO.StringIO()
animals1.export_to_csv_file(stream)
response.headers['Content-Type']='application/vnd.ms-excel'
response.headers['Content-disposition']='attachment;filename='+fname
response.write(stream.getvalue(), escape=False)
}}
Save to system file?, simple:
f = open('hello.csv', 'w')
f.write(stream.getvalue())
f.close()
Enjoy!
Không có nhận xét nào:
Đăng nhận xét