openpyxl 讀取excel2007

        from base_api import utils
        from openpyxl import load_workbook
        from iptv.models import TestUser
        wb = load_workbook(filename = 'F:\\aa.xlsx')
        sheet = wb .worksheets[0]
        data = []
        head = []
        for index,row in enumerate(sheet.rows):
            t = []
            for c in row:
                t.append(c.value)
                
            if index == 0:
                head = t
            else:
                data.append(dict(zip(head,t)))
                
        
        print 'data===',data
        result = []
        #{u'gc': u'103389391', u'zy': 1371986972.0, u'yyx': 107495135.0}
        for elem in data:
            if "gc" in elem:
                result.append(TestUser(userid = elem["gc"],ctype="gc"))
            
            if "zy" in elem:
                result.append(TestUser(userid = elem["zy"],ctype="zy"))
            
            if "yyx" in elem:
                result.append(TestUser(userid = elem["yyx"],ctype="yyx"))
                
        print len(result),result
        while result:
            p = result[:3000]
            with transaction.atomic():
                for e in  p:
                    e.save()
                    
            result = result[3000:]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章