Split Each Excel Sheet Into Separate Files
13 December, 2022
1
1
0
Contributors
Overview
In this article, we will see how to split each Excel sheet into separate files. With the help of the xlwings Python module, we will first read the Excel file and then split it into separate files.
How to do?
Letβs have a look at the process step by step:
Step 1: Install the module given below.
Step 2: Import the following modules.
Step 3: Create a new Excel instance with xlwings.App, then set visibility to False if you donβt want the Excel window to appear. Then, using the books.open function, open the worksheet.
Step 4: We'll execute a loop to traverse each sheet. Copy each sheet to a new workbook using the api.copy method, activate the newly created workbook, save the workbook, and finally close the workbook.
Step 5: When you exit the excel sheet, you will notice that all of the sheets have been changed to new Excel files.
Code
Output
Before:
Before split
After:
All sheets are split into separate Excel files.
Wrap Up
In this tutorial, we take a look at the Python XLwings module. Using this module, we quickly and efficiently split each Excel Sheet into separate files.
Follow me on Twitter (@triposat).
Thanks!
python
excel
beginner
develevate
ms