473,473 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Copy data from different workbook into Master sheet using Python

3 New Member
I have to copy data from different workbooks and paste it into a master workbook. All the workbooks including the Master file are located in a folder: C:\Users\f65651\data

So far I have been able to copy data from only one workbook using the code below
Expand|Select|Wrap|Line Numbers
  1.  
  2. import openpyxl as xl
  3.  
  4. path1 ='C:\\Users\\f65651\data\\cq1.xlsx' #One of the doc
  5. #path3 = 'C:\\Users\\f65651\data\\cq2.xlsx'
  6. path2='C:\\Users\\f65651\\data\\Results.xlsx' #Master Workbook
  7.  
  8. wb1 = xl.load_workbook(filename=path1)
  9. ws1 = wb1.worksheets[0]
  10.  
  11. wb2= xl.load_workbook(filename=path2)
  12. ws2= wb2.worksheets[0]
  13.  
  14. for row in ws1:
  15.         for cell in row:
  16.             ws2[cell.coordinate].value=cell.value
  17. wb2.save(path2)
  18.  
I need to be able to do this to incorporate all the workbooks. So for example, Workbook 2 is 'C:\\Users\\f65651\data\\cq2.xlsx'. 3,4,5 and 6 data should also be copied into the Result master sheet.
I have tried storing them into dataframe but it messes up the format in the Result sheet, so using df is out of it! or if there is any other way around. Please kindly suggest.
Aug 27 '19 #1
0 1405

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: eyal | last post by:
Hello, I want to open 2 workbook, , lets say workbook1 and workbook2 now I want to copy data from a sheet name "TEST" in workbook2 and paste the data to a sheet named "TEST" in workbook. now...
1
by: manitmalik | last post by:
Hi, I am a fresher and being assigned a work in which i need a help . Actually i have been told to write a script in python which can get the current price of stocks going on in the market on the...
3
by: smith jones | last post by:
Hi all, Can you plz guide me as to how to write data to an excel sheet using C+ + code? Thnks very much for your help!!!
1
by: ShambhuHubli | last post by:
Hi ! I am developing front end for some application using Python Tkinter. And I am new to this GUI development. In my application, I have to create buttons other than square or rectangle. I want...
5
by: tsanthoshk | last post by:
Hi All I am trying to read and modify input excel file. when i update the data in excel sheet already existing format is washing out. It mean if excel sheet contain colors those are not appearing...
1
by: Maninder Karir | last post by:
Hi, Basically I have 3 workbooks (A, B and C) Workbook A is used to retrieve all the information Workbook B contains a number of Lists used in workbook A (including a list of suppliers)...
1
by: DerrickProcurement | last post by:
I have no visual basic experience and all answers I have found required that I had some experience. I hope the questions is simple and that a professional can easily provide me with the proper code...
6
by: ronparker | last post by:
Hello, This is my first time posting and just my second day using python on mysql, so please be patient with me. I should also say, I am using a linux machine. Using python I was able to make a...
5
by: scrapcode | last post by:
Hi everyone. I'm trying to write a macro to copy data from one Excel sheet to another in the same workbook when a certain criteria is met. My data table is an import from an Access DB. After the...
2
by: Fatman003 | last post by:
I have to copy data from 6 workbooks and paste it into a master workbook. All the workbooks are located in a folder on my desktop: C:\Users\f6565\Desktop\data The workbooks contain a sheet named...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.