测试自动化学习7

python读取Excel

import xlrd


book = xlrd.open_workbook('my_user-bak.xls')
sheet = book.sheet_by_index(0)
print(sheet.row_values(0))  # 某一行数据
print(sheet.col_values(0))  # 某一列数据
print(sheet.cell(0,0).value)  # 某个单元格的数据
print(sheet.cell(1,2).value)  # 某个单元格的数据
print(sheet.nrows)  # 总共多少行
print(sheet.ncols)  # 总共多少列

print('----')
for i in range(sheet.nrows):  # 打印所有行
    print(sheet.row_values(i))

猜你喜欢

转载自www.cnblogs.com/fatenet/p/10879092.html