对比表格相同列填充数据

import xlrd,xlwt
from tkinter import filedialog, messagebox
from xlutils.copy import copy#导入模块
path_z = filedialog.askopenfilenames(filetypes=[("文本", "xls")], title="请选择总表")
path_f = filedialog.askopenfilenames(filetypes=[("文本", "xls")], title="请选择分表")

wb= xlrd.open_workbook(path_z[0])
ws = wb.sheet_by_name("瓶窑镇乱占耕地建房整体情况分析表")
nwb=copy(wb)
nws=nwb.get_sheet("瓶窑镇乱占耕地建房整体情况分析表")

wb1 = xlrd.open_workbook(path_f[0])
ws1 = wb1.sheet_by_index(0)
for row in range(1,ws.nrows):
    cell = ws.cell_value(row,1)
    for row1 in range(1,ws1.nrows):
        cell1 = ws1.cell_value(row1,4)
        val1 = ws1.cell_value(row1,5)
        if cell1 == cell:
            nws.write(row,3,val1)

nwb.save(r"C:\Users\Administrator\Desktop\统计\11-23\部图版\1.xls")



你可能感兴趣的:(excel)