python 은 xlwt 모듈 을 통 해 웹 페이지 에 엑셀 파일 을 직접 생 성하 고 다운로드 합 니 다.

818 단어 Python
다음으로 전송:http://www.sharejs.com/codes/python/7265
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()

좋은 웹페이지 즐겨찾기