import openpyxl import osfile_name = "file1.xlsx" if os.path.exists(file_name):print("文件存在")#读数据workbook = openpyxl.load_workbook(file_name)sheet = workbook["Sheet1"]list_all = [] # 放所有数据的listfor row in sheet.rows:cellnew = [] # 行listfor cell in row:cellnew.append(cell.value)list_all.append(cellnew)print(list_all)# file_name.close()#写数据wb=openpyxl.Workbook()wb.create_sheet("Sheet1")sheet1=wb['Sheet1']for row in range(1,len(list_all)+1):#print("row",row)for column in range(1,len(list_all[row-1])+1):# print("column",column) sheet1.cell(row,column).value=list_all[row-1][column-1]wb.save("file2.xlsx")else:print("文件不存在")