import xlrd
#只能读不能写
book = xlrd.open_workbook('test.xlsx') #打开一个excel
sheet = book.sheet_by_index(0)#根据顺序获取sheet
sheet1 = book.sheet_by_index(1)
# sheet2 = book.sheet_by_name('work_content')#根据sheet页名字获取sheet
# print(sheet.cell(0,0).value)#指定行和列获取数据
# print(sheet.cell(0,1).value)
# print(sheet.cell(0,2).value)
# print(sheet.cell(0,3).value)
print(sheet.ncols)#获取excel里面有多少列
print(sheet.nrows)#获取excel里面有多少行
#for i in range(sheet.nrows):#0 1 2 3 4 5
# print(sheet.row_values(i))#获取第几行的数据
for i in range(1): #循环获取第一列的内容
print(sheet.col_values(i))#获取第几列的数据
a=set(sheet.col_values(i))
print(a)
for i in range(1):
print(sheet1.col_values(i))#获取第几列的数据
b=set(sheet1.col_values(i))
print(b)
print(a-b) # 差集
print(a&b) # 交集
print(a|b) # 并集
print(a^b) # 反交集 # 两个集合中单独存在的数据 #相当于 (a|b)-(a&b)
python 读取excel内容