import openpyxl import os file_name = "file1.xlsx" if os.path.exists(file_name): print("文件存在") #读数据 workbook = openpyxl.load_workbook(file_name) sheet = workbook["Sheet1"] list_all = [] # 放所有数据的list for row in sheet.rows: cellnew = [] # 行list for 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("文件不存在")
标签:读取数据,column,list,excel,写入,file,print,row From: https://www.cnblogs.com/mghhzAnne/p/18620593