
Odoo中文社区可以通过以下两个域名访问:shine-it.net , odoo.net.cn
由于系统升迁的原因,本论坛部分较早期的内容存在格式和链接损坏失效的问题,并非本论坛系统本身的缺陷,望谅解
本社区没有维护任何QQ群讨论组,任何与本社区同名的QQ群讨论组的言论与本社区无关!
开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号
如果您登录系统碰到问题,请在微信公众号留言:
用wizard导入excel数据
-
作为一个quick note吧。
OE里的csv导入数据功能形同摆设,通俗地说就是弱爆了。
今天尝试一下用excel文件来导入数据。
在python里读取excel格式的lib很多,这里我选用的是xlrd。
上代码先:<br /># -*- coding: utf-8 -*-<br /><br />from osv import osv, fields<br />import time, xlrd, base64<br /><br /><br />class bank_bill_import(osv.osv_memory):<br /> <br /> _name = "fg_account.bank_bill.import.wizard"<br /> _description = "导入账单"<br /> <br /> _columns = {<br /> 'excel': fields.binary('excel文件', filters='*.xls'),<br /> }<br /> <br /> def import_bill(self, cr, uid, ids, context=None):<br /> for wiz in self.browse(cr,uid,ids):<br /> if not wiz.excel: continue<br /> <br /> excel = xlrd.open_workbook(file_contents=base64.decodestring(wiz.excel))<br /> sh = excel.sheet_by_index(0)<br /> print sh.name, sh.nrows, sh.ncols<br /> for rx in range(sh.nrows):<br /> for ry in range(sh.ncols):<br /> print sh.cell(rx, ry).value<br /> #这里做爱做的事情<br /> <br /> return {'type': 'ir.actions.act_window_close'}<br />
其实重点就在于:excel = xlrd.open_workbook(file_contents=base64.decodestring(wiz.excel))
-
Good 多谢分享....
-
这代码写在那里呢?
-
回楼上的 就是一个wizard..