Python-excel按指定顺序自动排序

import openpyxl

wb1=openpyxl.load_workbook('tsp_result.xlsx')


wb2=openpyxl.load_workbook('144.xlsx')

sheet1=wb1.get_active_sheet()


sheet2=wb2.get_active_sheet()


for i in range(1,146):
    te=0   #一定要先初始化为一个int型
    te=(sheet1.cell(row=i,column=1).value) #强制类型转化 不初始化不能完成赋值!
    sheet1.cell(row=i,column=2).value=sheet2.cell(row=te,column=2).value
    
wb1.save('tsp_result.xlsx')  #保存才能更新值

猜你喜欢

转载自blog.csdn.net/qq_41093189/article/details/81221662
今日推荐