0

I've been trying for a while to make tablib work with web2py without luck. The code is delivering a .xls file as expected, but it's corrupted and empty.

import tablib 
data = []

headers = ('first_name', 'last_name')
data = tablib.Dataset(*data, headers=headers)

data.append(('John', 'Adams'))
data.append(('George', 'Washington'))


response.headers['Content-Type']= 'application/vnd.ms-excel;charset=utf-8'
response.headers['Content-disposition']='attachment; filename=test.xls'
response.write(data.xls, escape=False)

Any ideas?? Thanks!

Agustin.Ferreira
  • 311
  • 1
  • 3
  • 11

1 Answers1

0

Per http://en.wikipedia.org/wiki/Process_state , response.write is documented as serving

to write text into the output page body

(my emphasis). data.xls is not text -- it's binary stuff! To verify that is indeed the cause of your problem, try using data.csv instead, and that should work, since it is text.

I believe you'll need to use response.stream instead, to send "binary stuff" as your response (or as an attachment thereto).

Alex Martelli
  • 854,459
  • 170
  • 1,222
  • 1,395