python xlrd/ 库我常用的命令
xlrd
打开文件:
def open_excel(file='testfile.xlsx'):
try:
data = xlrd.open_workbook(file,encoding_override="utf-8")
return data
except Exception as e:
print(str(e)+'mmmm')
取出数据:
filename = settings.filename
My_workbook = readInput.open_excel(filename)
all_sheets_list = My_workbook.sheets()
sheet1=all_sheets_list[0]#取出sheet1
按列取出:
col_dict = locals()#动态创建变量名
amount_cols = sheet1.ncols
for i,s in enumerate(range(amount_cols)):
col_dict['col_%s'%(i)] = sheet1.col_values(s)
#按列取出数值存放在col_i中