第一种方法:
import xlrd
workbook = xlrd.open_workbook("D:\pycharm\memeda\config\TestCase.xlsx")
worksheets = workbook.sheet_names()
print("workbook is %s" % worksheets)
# 定位到sheet1
worksheet1 = workbook.sheet_by_name(u"Sheet1")
""""
通过worksheet1 = workbook.sheets()[0]
或者
worksheet1 = workbook.sheet__by_name
遍历所有sheet对象
for workbook_name in woeksheets:
workbook = workbook.sheet_by_name(worksheet_name)"""
# 遍历所有sheet1中所有行row
num_rows = worksheet1.nrows
for curr_row in range(num_rows):
row = worksheet1.row_values(curr_row)
print("row%s is %s" % (curr_row, row))
# 遍历sheet1中所有列col
num_cols = worksheet1.ncols
for curr_col in range(num_cols):
col = worksheet1.col_values(curr_col)
print("row%s is %s" % (curr_col, col))
# 遍历所有的单元格cell
for rown in range(num_rows):
for coln in range(num_cols):
cell