Python Openpyxl, copy and paste from a list of fields in a directory

  openpyxl, operating-system, python-3.x

good day !

I’m new at Python and I’m trying to do some script to practice,
Is an old VBA Script that I want to change/improve to Python,

The idea is COPY/PASTE from a list of directory:
COPY a list of cells from diffrentes fields and PASTE in a one Summary table.

wants to copy some vertical/column and paste in horizontal/row,

    import os 
    import openpyxl as xl 
    from openpyxl import load_workbook 


    path = "D:Learn_Codemacro Excel VBAdata"
    files = os.listdir(path)

    for f in files :

        # set file path
        fileinput = f  #### HERE I NEED HELP !last path or one path D:Learn_Codemacro Excel VBAdatadataN279.xlsm
        fileoutput = "D:Learn_Codemacro Excel VBAdataaprendiendo.xlsm"

        # load demo.xlsx 
        wb=load_workbook(f)
        ws2=load_workbook(fileoutput)
        # get Sheet
        source=wb.get_sheet_by_name('mesures')
        destination=ws2.get_sheet_by_name('test')

        for n in range (1,5) :
            for i in range (3,33):
                c = source.cell(row = i, column = 6)
                destination.cell(row = n, column = (i-2)).value = c.value  

        ws2.save(fileoutput)


        print(f)

I got one ERROR/BUG in files = os.listdir(path) ,
enter image description here

I will appreciate any advice or HELP,

Thanks in advance,
Zamir AFRICANO

Source: Python-3x Questions

LEAVE A COMMENT