Jul-15-2020, 09:58 PM
Hello,
Thanks for the reply everything seems to be working this way, it's a little different then what you had suggested. I'm now stuck on trying to figure out how to look at ws1 column F starting at row 4 and count how many times the value 0 occurs. And then take how many time that value occurs and write it to ws3 column M row 2.
Thanks for the reply everything seems to be working this way, it's a little different then what you had suggested. I'm now stuck on trying to figure out how to look at ws1 column F starting at row 4 and count how many times the value 0 occurs. And then take how many time that value occurs and write it to ws3 column M row 2.
import openpyxl as xl; import os input_dir = 'C:\\work\\comparison\\NNM' template = 'C:\\work\\comparison\\template.xlsx' summary = 'C:\\work\\comparison\\Summary.xlsx' newFile = 'Comparison.xlsx' files = [file for file in os.listdir(input_dir) if os.path.isfile(file) and file.endswith(".xlsx")] wb3 = xl.load_workbook(template) ws3 = wb3.worksheets[0] i=0 ii=0 for file in files: input_file = os.path.join(input_dir, file) wb1=xl.load_workbook(input_file) ws1=wb1.worksheets[0] wb2 = xl.load_workbook(summary) ws2 = wb2.worksheets[1] ws3[f'A{i+2}']=ws1['A1'].value[28:] ws3[f'D{i+2}']=ws1['B4'].value ws3[f'E{i+2}']=ws1['D4'].value ws3[f'I{i+2}']=ws1['B'][-1].value ws3[f'J{i+2}']=ws1['D'][-1].value ws3[f'O{i+2}']=ws1['E'][-1].value ws3[f'N{i+2}']=ws2[f'I{ii+6}'].value i += 1 ii +=1 wb3.save(newFile)