3 import openpyxl 4 5 def write_xlsx(value, path, sheet_name='Sheet1'): 6 7 index = len(value) 8 workbook = openpyxl.Workbook() 9 sheet = workbook.active 10 sheet.title = sheet_name 11 for i in range(index): 12 for j in range(len(value[i])): 13 sheet.cell(row=i+1, column=j+1, value=str(value[i][j])) 14 workbook.save(path) 15 print('xlsx表格写入数据成功!') 16 17 def read_xlsx(path, sheet_name='Sheet1'): 18 workbook = openpyxl.load_workbook(path) 19 sheet = workbook[sheet_name] 20 for row in sheet.rows: 21 for cell in row: 22 print(cell.value, " ", end="") 23 print(' ') 24 # print('xlsx表格数据读取成功!') 25 26 write_xlsx(detail, data_path, 'Sheet1') 27 read_xlsx(data_path, 'Sheet1')