Jul-14-2020, 03:46 PM
Hello,
I'm trying to copy certain cells from ws, and paste them into certain cells in ws2, what I have isn't doing this. It's just creating an output file called 'NNM_Comparison.xlsx' which is fine but it has none of the data in it.
I'm trying to copy certain cells from ws, and paste them into certain cells in ws2, what I have isn't doing this. It's just creating an output file called 'NNM_Comparison.xlsx' which is fine but it has none of the data in it.
import openpyxl as xl; import os input_dir = 'C:\\work\\comparison\\NMN' template = 'C:\\work\\comparison\\template.xlsx' newFile = 'NNM_Comparison.xlsx' files = [file for file in os.listdir(input_dir) if os.path.isfile(file) and file.endswith(".xlsx")] for file in files: input_file = os.path.join(input_dir, file) wb1=xl.load_workbook(input_file) ws=wb1.worksheets[0] ws['A1'].value[28:] ws['B4'].value ws['D4'].value ws['B5666'].value ws['D5666'].value wb2 = xl.load_workbook(template) ws2 = wb2.worksheets[0] ws2['A2']==ws['A1'] ws2['D2']==ws['B4'] ws2['E2']==ws['D4'] ws2['I2']==ws['B5666'] ws2['J2']==ws['D5666'] output_file = (newFile) wb2.save(output_file)