python 2.7 - Way to compare two excel files and CSV file -
i need compare 2 excel files , csv file, write data 1 excel file another.
it looks this:
csv file names compare. example (spam, eggs)
first excel file name , value of it. example (spam, 100)
second excel file name. example (eggs)
now, when input file (second) program need ensure eggs == spam csv file , save value of 100 eggs.
for operating on excel files i'm using openpyxl
, csv i'm using csv
.
can count on help? maybe there better libraries that, because trials proved total failure.
got myself. complex way, works wanted to. glad tips it.
import openpyxl import numpy np lines = np.genfromtxt("csvtest.csv", delimiter=";", dtype=none) compdict = dict() in range(len(lines)): compdict[lines[i][0]] = lines[i][1] wb1 = openpyxl.load_workbook('inputtest.xlsx') wb2 = openpyxl.load_workbook(filename='spistest.xlsx') ws = wb1.get_sheet_by_name('sheet1') spis = wb2.get_sheet_by_name('sheet1') row in ws.iter_rows(min_row=1, max_row=ws.max_row, min_col=1): cell in row: if cell.value in compdict: wiersz in spis.iter_rows(min_row=1, max_row=spis.max_row, min_col=1): komorka in wiersz: if komorka.value == compdict[cell.value]: cena = spis.cell(row=komorka.row, column=2) ws.cell(row=cell.row, column=2, value=cena.value) wb1.save('inputtest.xlsx') wb2.close()
Comments
Post a Comment