用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))