You can use openpyxl to transfer an excel range from one workbook to another but into a distinct range by following these steps:
Open the source workbook using openpyxl:
from openpyxl import load_workbook src_wb = load_workbook('source_workbook.xlsx') src_ws = src_wb['Sheet1'] # Replace 'Sheet1' with the name of the source worksheet
Select the range from the source worksheet that you want to transfer:
src_range = src_ws['A1:C4'] # Replace 'A1:C4' with the address of the range you want to transfer
Open the destination workbook using openpyxl:
dest_wb = load_workbook('destination_workbook.xlsx') dest_ws = dest_wb['Sheet1'] # Replace 'Sheet1' with the name of the destination worksheet
Select the destination range where you want to transfer the data:
dest_range = dest_ws['A5:C8'] # Replace 'A5:C8' with the address of the destination range
Copy the source range to the destination range:
for row in src_range: for cell in row: dest_ws[cell.coordinate].value = cell.value
Save the destination workbook:
dest_wb.save('destination_workbook.xlsx')
This should transfer the data from the source range to the destination range in the destination workbook.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2022-04-08 11:00:00 +0000
Seen: 12 times
Last updated: Mar 03 '22
How can I set up Gunicorn with a Django Project?
Looking for a Python Module that finds Tags for a Text describing its Content
Need a Function in Python to remove entries less than 2 digits from an Array
How can I convert a Document in Python?
How can I program a Loop in Python?
How can I enable Python Code Highlighting in Askbot?