首页 > 其他 > 详细

openerp用wizard导入excel数据

时间:2014-02-10 17:00:57      阅读:372      评论:0      收藏:0      [点我收藏+]

来自:http://blog.csdn.net/yumingbuzhongyao/article/details/18669183

作为一个quick note吧。
OE里的csv导入数据功能形同摆设,通俗地说就是弱爆了。
今天尝试一下用excel文件来导入数据。
在python里读取excel格式的lib很多,这里我选用的是xlrd。

上代码先:

 

bubuko.com,布布扣
# -*- coding: utf-8 -*-

from osv import osv, fields
import time, xlrd, base64


class bank_bill_import(osv.osv_memory):
    
    _name = "fg_account.bank_bill.import.wizard"
    _description = "导入账单"
    
    _columns = {
        excel: fields.binary(excel文件, filters=*.xls),
    }
    
    def import_bill(self, cr, uid, ids, context=None):
        for wiz in self.browse(cr,uid,ids):
            if not wiz.excel: continue
            
            excel = xlrd.open_workbook(file_contents=base64.decodestring(wiz.excel))
            sh = excel.sheet_by_index(0)
            print sh.name, sh.nrows, sh.ncols
            for rx in range(sh.nrows):
                for ry in range(sh.ncols):
                    print sh.cell(rx, ry).value
                    #这里做爱做的事情
            
        return {type: ir.actions.act_window_close}
bubuko.com,布布扣

其实重点就在于:

excel =xlrd.open_workbook(file_contents=base64.decodestring(wiz.excel))

openerp用wizard导入excel数据

原文:http://www.cnblogs.com/chjbbs/p/3543025.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!