Python | How to copy data from one excel sheet to another Last Updated : 03 Oct, 2019 Comments Improve Suggest changes Like Article Like Report In this article, we will learn how to copy data from one excel sheet to destination excel workbook using openpyxl module in Python. For working with excel files, we require openpyxl, which is a Python library that is used for reading, writing and modifying excel (with extension xlsx/xlsm/xltx/xltm) files. It can be installed using the following command: Sudo pip3 install openpyxl For copying one excel file to another, we first open both the source and destination excel files. Then we calculate the total number of rows and columns in the source excel file and read a single cell value and store it in a variable and then write that value to the destination excel file at a cell position similar to that of the cell in source file. The destination file is saved. Procedure - 1) Import openpyxl library as xl. 2) Open the source excel file using the path in which it is located. Note: The path should be a string and have double backslashes (\\) instead of single backslash (\). Eg: Path should be C:\\Users\\Desktop\\source.xlsx Instead of C:\Users\Admin\Desktop\source.xlsx 3) Open the required worksheet to copy using the index of it. The index of worksheet ānā is ān-1ā. For example, the index of worksheet 1 is 0. 4) Open the destination excel file and the active worksheet in it. 5) Calculate the total number of rows and columns in source excel file. 6) Use two for loops (one for iterating through rows and another for iterating through columns of the excel file) to read the cell value in source file to a variable and then write it to a cell in destination file from that variable. 7) Save the destination file. Python3 # importing openpyxl module import openpyxl as xl; # opening the source excel file filename ="C:\\Users\\Admin\\Desktop\\trading.xlsx" wb1 = xl.load_workbook(filename) ws1 = wb1.worksheets[0] # opening the destination excel file filename1 ="C:\\Users\\Admin\\Desktop\\test.xlsx" wb2 = xl.load_workbook(filename1) ws2 = wb2.active # calculate total number of rows and # columns in source excel file mr = ws1.max_row mc = ws1.max_column # copying the cell values from source # excel file to destination excel file for i in range (1, mr + 1): for j in range (1, mc + 1): # reading cell value from source excel file c = ws1.cell(row = i, column = j) # writing the read value to destination excel file ws2.cell(row = i, column = j).value = c.value # saving the destination excel file wb2.save(str(filename1)) Source File: Output: Comment More infoAdvertise with us Next Article Python | How to copy data from one excel sheet to another K kmaniratha Follow Improve Article Tags : Python python-utility Practice Tags : python Similar Reads How to Automate an Excel Sheet in Python? Before you read this article and learn automation in Python, let's watch a video of Christian Genco (a talented programmer and an entrepreneur) explaining the importance of coding by taking the example of automation.You might have laughed loudly after watching this video, and you surely might have u 8 min read How to Convert Excel to XML Format in Python? Python proves to be a powerful language when the requirement is to convert a file from one format to the other. It supports tools that can be employed to easily achieve the functionality. In this article, we'll find out how we will convert from an Excel file to Extensible terminology (XML) files wit 3 min read How to add timestamp to excel file in Python In this article, we will discuss how to add a timestamp to an excel file using Python. Modules requireddatetime: This module helps us to work with dates and times in Python.pip install datetimeopenpyxl: It is a Python library used for reading and writing Excel files.pip install openpyxltime: This mo 2 min read How to Convert JSON to Excel in Python JSON (JavaScript Object Notation) is a widely used data format that is both easy to read and write for humans and simple for machines to parse and generate. However, there may be times when we need to convert this JSON data into an Excel spreadsheet for analysis or reporting. In this article, we'll 3 min read Export Data From Mysql to Excel Sheet Using Python We are given a MySQL database and our task is to export the data into an excel sheet using Python. In this article, we will see how to export data from MySQL to Excel Sheets using Python. Export Data From Mysql to Excel Sheet Using PythonBelow are some of the ways by which we can export data from My 3 min read How to Filter and save the data as new files in Excel with Python Pandas Sometimes you will want to filter and save the data as new files in Excel with Python Pandas as it can help you in selective data analysis, data organization, data sharing, etc. In this tutorial, we will learn how to filter and save the data as new files in Excel with Python Pandas. This easy guide 3 min read How to convert a Python datetime.datetime to excel serial date number This article will discuss the conversion of a python datetime.datetime to an excel serial date number. The Excel "serial date" format is actually the number of days since 1900-01-00. The strftime() function is used to convert date and time objects to their string representation. It takes one or more 3 min read How to Automate Google Sheets with Python? In this article, we will discuss how to Automate Google Sheets with Python. Pygsheets is a simple python library that can be used to automate Google Sheets through the Google Sheets API. An example use of this library would be to automate the plotting of graphs based on some data in CSV files that w 4 min read How To Extract Data From Common File Formats in Python? Sometimes work with some datasets must have mostly worked with .csv(Comma Separated Value) files only. They are really a great starting point in applying Data Science techniques and algorithms. But many of us will land up in Data Science firms or take up real-world projects in Data Science sooner or 6 min read Fetch JSON URL Data and Store in Excel using Python In this article, we will learn how to fetch the JSON data from a URL using Python, parse it, and store it in an Excel file. We will use the Requests library to fetch the JSON data and Pandas to handle the data manipulation and export it to Excel.Fetch JSON data from URL and store it in an Excel file 3 min read Like