First import xlwt、xlrd The first txt Read out all the documents , Then use a loop to write xlsx The file of . import xlwt import xlrd book = xlwt.Workbook() ws = book.add_sheet('Sheet') f = open('txt file name ', 'r+') data = f.readlines() for i in range(len(data)): row = data[i].split() for j in range(len(row)): ws.write(i, j, row[j]) book.save(' Saved file name ') f.close()