python3 解析.xlsx

首先安装xlrd库,安装方法:pip install xlrd

import xlrd

#打开excel
wb = xlrd.open_workbook('test_user_data.xlsx')

#按工作簿定位工作表
sh = wb.sheet_by_name('TestUserLogin')

print(sh.nrows)#有效数据行数
print(sh.ncols)#有效数据列数
print(sh.cell(0,0).value)#输出第一行第一列的值
print(sh.row_values(0))#输出第一行的所有值

#将数据和标题组合成字典
print(dict(zip(sh.row_values(0),sh.row_values(1))))

#遍历excel,打印所有数据
for i in range(sh.nrows):
    print(sh.row_values(i))

#遍历excel,第一列不为空的值
for i in range(sh.nrows):
	if sh.cell(i,0).value:
	    print(int(sh.cell(i,0).value))

参考链接:

https://www.cnblogs.com/huny/p/13054389.html

猜你喜欢

转载自blog.csdn.net/cocos2dGirl/article/details/118893525