import xlrd
def extract(inpath):
data = xlrd.open_workbook(inpath, encoding_override=”utf-8″)
table = data.sheets()[0] # 选定表
nrows = table.nrows # 获取行号
ncols = table.ncols # 获取列号
all_info =[]
teacher = getnew(inpathnew)
print(teacher)
# print(nrows)
for i in range(0, nrows): # 第0行为表头
if i == 10:
break
else:
alldata = table.row_values(i) # 循环输出excel表中每一行,即所有数据
result = alldata[0] + “、” + alldata[1] + “、” + alldata[2] + “、” + alldata[3] + “、” + alldata[4] # 取出表中第二列数据
name = “刘诗诗”
data = name in result
if data:
index = i
same_name = name
#print(result)
def getnew(inpathnew):
data = xlrd.open_workbook(inpathnew, encoding_override=”utf-8″)
table = data.sheets()[0] # 选定表
nrows = table.nrows # 获取行号
ncols = table.ncols # 获取列号
all_info =[]
for i in range(1, nrows): # 第0行为表头
alldata = table.row_values(i) # 循环输出excel表中每一行,即所有数据
result = alldata
#result = alldata[0] + “、” + alldata[1] + “、” + alldata[2] + “、” + alldata[3] + “、” + alldata[4] + “、” + alldata[5] # 取出表中第二列数据
all_info.append(result)
print(all_info)
#all_info = (2, 5, 8, 10, 8, 12, 23, 3, 2, 3, 5)
import itertools
original_list = all_info
new_merged_list = list(itertools.chain(*original_list))
print(new_merged_list)
arr = new_merged_list
print(arr)
n = len(arr)
for i in range(0, n):
for j in range(i + 1, n):
if (arr[i] == arr[j]):
print(“%s,%s” % (arr[i], arr[j]))
# # 定义列表
# l = [“a”, “b”, “c”, “a”, “b”, “c”, “a”]
# # 获取第一个”a”的下标
# index_one = l.index(“a”)
# # 从第一个”a”的下一个位置开始查找, 所以加1
# print(l.index(“a”, index_one + 1))
#return all_info
inpath = (“111.xlsx”) # excel文件所在路径
inpathnew = (“222.xlsx”) # excel文件所在路径
#extract(inpath)
getnew(inpathnew)