talk is cheap,show you the code
*需要安装xlwt
import xlwt
import web
def download_report(query_set)
file_name="test.xls"
"""设置web header"""
web.header('Content-type','application/vnd.ms-excel') #指定返回的类型
web.header('Transfer-Encoding','chunked')
web.header('Content-Disposition','attachment;filename="%s"'%file_name) #设定用户浏览器显示的保存文件名
"""开始制作表格"""
wb=xlwt.Workbook()
wb.encoding='utf8' #设置字符编码
ws=wb.add_sheet('1')
"""表头开始"""
ws.write(0,0,u'序号')
ws.write(0,1,u'时间')
"""设置宽度"""
col=ws.col(0)
col.width=256*15 #15个字符宽度
"""表体开始"""
count=1
for item in query_set:
if item.get('create_user') is not None:
ws.write(count,0,count)
ws.write(count,1,str(item.get('create_date')))
count+=1
sio=StringIO.StringIO()
wb.save(sio)
return sio.getvalue()