如何使用Python读取Excel指定的行列数据
# 导包
import xlrd
def get_exceldate(filepath,sheet_name,casename):
print(filepath)
res_list = []
# 获取指定的表对象
work_book = xlrd.open_workbook(filepath,formatting_info=True)
# 操作指定的表单
work_sheet = work_book.sheet_by_name(sheet_name)
count =0
# 获取第0列全部数据作为遍历对象
for one_col in work_sheet.col_values(0):
# 防止列中有多余数据 进行判断
if casename in one_col:
#获取每行第九列的数据
req_body = work_sheet.cell(count,9).value
#获取每行第十一列的数据
resp_exp = work_sheet.cell(count,11).value
#将数据 加入到列表中
res_list.append(req_body)
#将数据 加入到列表中
res_list.append(resp_exp)
print(one_col)
if __name__ == '__main__':
get_exceldate("D:/testdata.xls","访问",'access')