While processing the Excel files programmatically, you may need to copy data from one Excel sheet to another. Also, you may have to copy data from a sheet in one Excel workbook to another. To deal with such cases, this article shows how to copy data from Excel sheets in Python. We will explicitly cover copying sheets’ data within an Excel file or from one file to another in Python.
- Python Library to Copy Data from Excel Sheets - Free Download
- How to Copy Data from Excel Sheets in Python
- Copy Data from One Excel Sheet to Another in Python
- Copy Excel Sheet’s Data from One Workbook to Another
- Get a Free License
Python Library to Copy Data from Excel Sheets - Free Download
To copy data from Excel sheets, we’ll use the spreadsheet manipulation capabilities of Aspose.Cells for Python. The library provides a wide range of features to generate and process Excel files from within your Python applications. You can either download its package or install it from PyPI using the following command.
pip install aspose-cells
How to Copy Data from Excel Sheets in Python
First, let’s have a look at how we can copy data from one sheet to another in an Excel file using Aspose.Cells for Python. The following simple steps demonstrate how to perform this operation.
- Load the Excel file.
- Copy data from worksheet using its name.
- Save the updated Excel file.
When you copy the data, a new worksheet is created in the Excel workbook containing that data. Now, let’s see how to copy the Excel worksheets’ data using Python code.
Copy Data from One Excel Sheet to Another in Python
The following are the steps to copy data from one Excel sheet to another in Python.
- Load Excel file using Workbook class.
- Get reference of the worksheets collection in an object using Workbook.getWorksheets() method.
- Use WorksheetsCollection.addCopy(sheetName) method to copy data from the worksheet by providing its name.
- Save the updated Excel file using Workbook.save(fileName) method.
The following code sample shows how to copy data from one Excel sheet to another in Python.
Python: Copy Excel Sheet’s Data from One Workbook to Another
Now, let’s have a look at how to copy a worksheet’s data from one Excel workbook to another. The following are the steps to perform this operation.
- Load the destination Excel file using Workbook class.
- Similarly, load the source Excel file using Workbook class.
- Copy data from source to destination worksheet using Workbook1.getWorksheets().get(index).copy(Workbook2.getWorksheets().get(index)) method.
- Save the destination Excel file using Workbook.save(fileName) method.
The following code sample shows how to copy worksheet’s data from one Excel file to another in Python.
Python Library to Copy Data from Excel Sheets - Get a Free License
You can use Aspose.Cells for Python without evaluation limitations by getting a free temporary license.
Conclusion
In this article, you have learned how to copy data from Excel sheets in Python. We have explicitly covered how to copy worksheet data within an Excel file or from one file to another. Besides, you can explore other features of Aspose.Cells for Python using the documentation. In case you would have any queries, feel free to post to our forum.