0
votes

I'm new to Python and want to compile values located in the same address from different Excel sheets to a single one. My code, shown below is giving me trouble. Could you help me please? (the code shown below pretends to copy from one workbook to another, my final code should access many workbooks and compile all desired fields into a single Excel sheet)

import openpyxl as opl

wb1 = opl.load_workbook('C:/users/Gabriel/documents/python/python-excel/data1.xlsx')

wb2 = opl.load_workbook('c:/users/Gabriel/documents/python/python-excel/data2.xlsx')
sheet1=wb1.active

sheet2=wb2.active

a1=sheet1['A1']

a2=sheet1['A2']

a3=sheet1['A3']


sheet2['B1']=a1

sheet2['B2']=a2

sheet2['B3']=a3

wb2.save('c:/users/Gabriel/documents/python/python-excel/data2.xlsx')
1

1 Answers

0
votes

Welcome! It is really hard to tell what is your problem... Instead of asking for more details, let's exchange information, since you are new to Python that should work better. So... as a first guess - use sheet1['A1'].value respectively - for reading and writing.

If you are looking for code that reads Excel files and combine their data. Here is my example.

As a side note - I've heard that MS is going to use Python as their scripting language!