exceltojson

openpyxl 读取多个excle中的数据并保存到List中

我们两清 提交于 2020-08-20 01:11:59
def excel_to_json(file_name): wb = load_workbook(file_name) all_data = defaultdict(list) for sheet_name in wb.sheetnames: rows = list(wb[sheet_name].rows) title = [i.value for i in rows[0]] for row in rows[1:]: data = [i.value for i in row] all_data[sheet_name].append(dict(zip(title, data))) return all_data 来源: oschina 链接: https://my.oschina.net/u/4414119/blog/4321405