Read excel spreadsheet .py

to xlrd Import 

# open the file and to get a book object:
book xlrd.open_workbook = (R & lt "D: \ S27 \ day68 \ Interface Test Example .xlsx")
Sheet = book.sheet_by_index (0)
Print (Sheet)

# Gets OK:
# Print (sheet.nrows)

# Gets the column:
# Print (sheet.ncols)

# get the contents of each line:
# row in for the Range (sheet.nrows):
# Print (sheet.row_values (row))

# get each column content:
# for COL in the Range (sheet.ncols):
# Print (sheet.col_values (COL))

# Gets the specified line content:
# Print (sheet.row_values (1))

# get title:
title = sheet.row_values (0 )
# Print (title)

L = []
# for additional lines:
for row in Range (. 1, sheet.nrows):
# Print (sheet.row_values (row))
l.append(dict(zip(title,sheet.row_values(row))))
print(l)

The results: [{ 'case_project': 'cnodejs project', 'case_description': 'get / topics theme Home', 'case_url': 'https://cnodejs.org/api/v1/topics',' case_method ':' get ',' case_params': '', 'case_expect': '{ "success": true}'}, { 'case_project': 'cnodejs project', 'case_description': 'get / topic /: id theme details' 'case_url': 'https://cnodejs.org/api/v1/topic/5433d5e4e737cbe96dcef312', 'case_method': 'get', 'case_params': '', 'case_expect': '{ "success": true}' }, { 'case_project': 'cnodejs project', 'case_description': '/ topic_collect / collect collection theme', 'case_url': 'https://cnodejs.org/api/v1/topic_collect/collect', 'case_method' : 'post', 'case_params': '', 'case_expect': '{"success": false}'}, {'case_project': 'cnodejs项目', 'case_description': 'post /topic_collect/de_collect 取消主题', 'case_url': 'https://cnodejs.org/api/v1//topic_collect/de_collect', 'case_method': 'post', 'case_params': '', 'case_expect': '{"success": false}'}, {'case_project': 'cnodejs项目', 'case_description': '/user/:loginname 用户详情', 'case_url': 'https://cnodejs.org/api/v1/user/alsotang', 'case_method': 'get', 'case_params': '', 'case_expect': '{"success":true}'}, {'case_project': 'cnodejs项目', 'case_description': '/ Message / mark_all Mark all read ',' case_url ':' https://cnodejs.org/api/v1/message/mark_all ',' case_method ':' post ',' case_params': '', 'case_expect' : '{ "success": false}'}, { 'case_project': 'v2EX project', 'case_description': 'get web information', 'case_url': 'https://www.v2ex.com/api/site /info.json ',' case_method ':' get ',' case_params': '', 'case_expect': '{ "title": "V2EX"}'}]Get web information ',' case_url ':' https://www.v2ex.com/api/site/info.json ',' case_method ':' get ',' case_params ':' ',' case_expect ':' { "title": "V2EX"} '}]Get web information ',' case_url ':' https://www.v2ex.com/api/site/info.json ',' case_method ':' get ',' case_params ':' ',' case_expect ':' { "title": "V2EX"} '}]


Guess you like

Origin www.cnblogs.com/zhang-da/p/12227396.html