xlrd를 이용하여 xls 파일의 데이터 가져오기

2250 단어
#coding:utf-8 import os 
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "www.settings") 

'''Django       1.7   ,        
import django
django.setup()
        django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.'''import djangoif django.VERSION >= (1, 7):#          django.setup()from keywork.models import DevDataimport xlrd #excel   data= xlrd.open_workbook('cs.xls') #    table = data.sheet_by_index(0) #     nrows = table.nrows #  ncols = table.ncols #  colnames =  table.row_values(0)
WorkList = []
x = y = z = 0for i in range(1,nrows):
    row = table.row_values(i) #     
    for j in range(0,ncols):        if type(row[j]) == float: #    float    int,    1   1.0   
            row[j] = int(row[j])    if row: #        
        if DevData.objects.filter(serv_id = row[0],user_flag=row[15]).exists():#              
            x = x + 1 #     
        else:
            y = y + 1 #     
            WorkList.append(DevData(serv_id=row[0], serv_state_name=row[1], acc_nbr=row[2], user_name=row[3], acct_code=row[4], product_id=row[5],
                                            mkt_chnl_name=row[6], mkt_chnl_id=row[7],mkt_region_name=row[8], mkt_region_id=row[9],mkt_grid_name=row[10],
                                            sale_man=row[11],sale_outlets_cd1_name=row[12], completed_time=row[13],remove_data=row[14], user_flag=row[15],
                                            pro_flag=row[16], service_offer_id=row[17],service_offer_name=row[18], finish_time=row[19],staff_name=row[20],
                                            staff_code=row[21],org_name=row[22],prod_offer_name=row[23],day_id=row[24],
                                            )
                                    )    else:
        z = z + 1     #     DevData.objects.bulk_create(WorkList)print '      ,  '+str(x)+' ,  '+str(y)+' , '+str(z)+'   !'
          APP,       ,          ,   (   APP     ) http://t.cn/R4vE2d7      5         ! 
  -   IT    ,       ,    ,             :www.wenaaa.com     APP,      ,     。
QQ 290551701          ,    ,   ,    !      ,      ,          IT      !

http://cxy.liuzhihengseo.com/497.html

좋은 웹페이지 즐겨찾기