1. 程式人生 > >python獲取excel數據

python獲取excel數據

int cmdb utf () -- 差集 xlsx mes bin

#!/usr/bin/python # --*-- coding: utf-8 --*-- import xlrd excel_file = "/data/script/cmdb_excel_2018_08_04_16_03.xlsx" csv_file = "/data/script/jms.xlsx" #################get old jms ip_list #################### workbook = xlrd.open_workbook(excel_file) sheet_name_list = workbook.sheet_names() ip_list = [] #ip_cols = sheet1.col_values(1) #print(ip_cols[1]) for i in range(0,4): sheet = workbook.sheet_by_index(i) ip_cols = sheet.col_values(1) ip_list.extend(ip_cols) ip_list.remove('IP') ip_list.remove('IP') ip_list.remove('IP') ip_list.remove('IP') #print(len(ip_list)) #for a in ip_list: # if ip_list.count(a) > 1: # print a #########################get new jms ip_list ############# workbook_new = xlrd.open_workbook(csv_file) new_sheet_name_list = workbook_new.sheet_names() new_ip_list = [] #ip_cols = sheet1.col_values(1) #print(ip_cols[1]) new_sheet = workbook_new.sheet_by_index(0) new_ip_cols = new_sheet.col_values(0) new_ip_list.extend(new_ip_cols) #new_ip_list.remove('IP') #print(new_ip_list) #print(len(new_ip_list)) ######################################################### ##############比較ip_list和new_ip_list的差集########## res = set(ip_list).difference(set(new_ip_list)) print(len(res)) for i in res: print(i)


python獲取excel數據