import xlwt
import StringIO
import web
urls = (
'/rim_request','rim_request',
'/rim_export','rim_export',
'/(.*)', 'index'
)
class rim_export:
#render = web.template.render('adsl')
def GET(self):
web.header('Content-type','application/vnd.ms-excel') #指定返回的类型
web.header('Transfer-Encoding','chunked')
web.header('Content-Disposition','attachment;filename="export.xls"')
wb=xlwt.Workbook()
wb.encoding='gbk'
ws=wb.add_sheet('1')
ws.write(0,1,'123') #如果要写中文请使用UNICODE
sio=StringIO.StringIO()
wb.save(sio) #这点很重要,传给save函数的不是保存文件名,而是一个StringIO流
return sio.getvalue()