Python Function to Read Excel Sheet by Name using xlrd
The function read_xlsx_by_sheet_name takes in two parameters, xlsxfile which is the path to the xlsx file and sheet_name which is the name of the sheet in the xlsx file that you want to read.
The function opens the xlsx file using xlrd.open_workbook and gets the sheet using wb.sheet_by_name.
It then creates an empty dictionary result_detail to store the data from the sheet.
The function then iterates over each row in the sheet, starting from the second row (index 1). For each row, it creates a dictionary using zip to combine the values from the first row (column names) as keys and the values from the current row as values.
It then adds this dictionary to the result_detail dictionary with the row index as the key.
Finally, it returns the result_detail dictionary containing the data from the sheet.
原文地址: https://www.cveoy.top/t/topic/pQcX 著作权归作者所有。请勿转载和采集!