上传的excel文件在内存里就能打开操作。
<br /><br />for wiz in self.browse(cr,uid,ids):<br /> if not wiz.excel: continue<br /> excel = xlrd.open_workbook(file_contents=base64.decodestring(wiz.excel))<br /> sh = excel.sheet_by_index(0)<br /> for rx in range(sh.nrows):<br /> print 'processing line ', rx<br />...<br /><br />
如果想生成excel文件并下载(参考下载翻译那个wizard一样,两个state: choose, get, 然后利用binary field,提供给用户下载的连接出来):
<br /><br />#.....从数据库取数据,计算,blahblah<br /><br /> book = xlwt.Workbook(encoding='utf-8')<br /> sheet = book.add_sheet(u'统计')<br /><br /> buf=cStringIO.StringIO()<br /> book.save(buf)<br /> <br /> out=base64.encodestring(buf.getvalue())<br /> <br /> self.write(cr, uid, ids, {'state':'get', 'data':out, 'name':this.name }, context=context)<br /><br /><br />