Python: Split Each Excel Sheet Into Separate Files (fast & easy)

preview_player
ะŸะพะบะฐะทะฐั‚ัŒ ะพะฟะธัะฐะฝะธะต

๐——๐—˜๐—ฆ๐—–๐—ฅ๐—œ๐—ฃ๐—ง๐—œ๐—ข๐—ก
โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€
This video will show you how to split each worksheet in Excel into a separate Excel file/workbook using Python instead of VBA. In particular, we will be using the xlwings library.

Remark: In the video, I have used the os dependent '.api' method to copy sheets.
Since xlwings version 0.22 the '.copy()' has been implemented.
Additionally, xlwings.App() can now be used as context manager in xlwings v0.24.3:
This will make sure that there are no zombie processes left over on Windows, even if you use a hidden instance and your code fails.
It is therefore recommended to use it whenever you can. Therefore I have adjusted the code as follows:

๐Ÿ‘ฉโ€๐Ÿ’ป ๐—ฃ๐˜†๐˜๐—ต๐—ผ๐—ป ๐—–๐—ผ๐—ฑ๐—ฒ:
from pathlib import Path
import xlwings as xw # pip install xlwings

EXCEL_FILE = Path(__file__).parent / 'YOUR_EXCEL_FILE.xlsx'
OUTPUT_DIR = Path(__file__).parent / 'Output'

# Create Output directory
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)

with xw.App(visible=False) as app:

๐—ง๐—ข๐—ข๐—Ÿ๐—ฆ ๐—”๐—ก๐—— ๐—ฅ๐—˜๐—ฆ๐—ข๐—จ๐—ฅ๐—–๐—˜๐—ฆ
โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€

๐—–๐—ข๐—ก๐—ก๐—˜๐—–๐—ง ๐—ช๐—œ๐—ง๐—› ๐— ๐—˜
โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€

โ˜• ๐—•๐˜‚๐˜† ๐—บ๐—ฒ ๐—ฎ ๐—ฐ๐—ผ๐—ณ๐—ณ๐—ฒ๐—ฒ?
ะ ะตะบะพะผะตะฝะดะฐั†ะธะธ ะฟะพ ั‚ะตะผะต
ะšะพะผะผะตะฝั‚ะฐั€ะธะธ
ะะฒั‚ะพั€

Great video, short and directly to the point. An example of how these tutorials should be. Thanks.

moretinga
ะะฒั‚ะพั€

Excellent tutorial!! For more tutorials like that, add more videos in this sense, as this would help us a lot! Hugs

qpeilcd
ะะฒั‚ะพั€

Great video, but the folders weren't exactly the way they were before. But it saved me a lot of work.
THANK YOU!

zeciconicaciojr
ะะฒั‚ะพั€

*What other Excel tasks would you like to automate?*

CodingIsFun
ะะฒั‚ะพั€

What are you talking about? Where do you type that in?

Raven-uguw
ะะฒั‚ะพั€

I have a workbook which contains 200 sheets in a single workbook, I want to combine it into 20 workbooks. ... I am doing via excel macro it takes 45 minutes. Can we do it via python!

MrMallesh
ะะฒั‚ะพั€

Excellent Explanation .. Thanks a lot for the video.

I have one doubt/question
1. We are splitting country basis excel, if we want to add one more sheet with product name?
how can we do

chatishwaranTSsathiyamoorthy
ะะฒั‚ะพั€

Thank you! Question: Is it possible to go the other way, take several excel files and combine into one excel file with multiple tabs?

kevinoverhead
ะะฒั‚ะพั€

How can I save One worksheet as a seperate workbook

bongadywili
ะะฒั‚ะพั€

I have multiple excel files, I want each file to be an excel sheet, how do we do that?

AhmadArafatAhmedArafat
ะะฒั‚ะพั€

Can you please include a video in splitting a long text file into multiple files with proper naming using some pattern matching?

rajeevmenon
ะะฒั‚ะพั€

if I have a folder with multiple excel files with the same amount of sheets how to I split all the files in the folder? and save them as the file name + sheet name?

ceciliepedersen
ะะฒั‚ะพั€

hello, can you split the excel file by the specific rows, and just cut the file to the half and mak anither excel file. Because I have a lot of rows in one file and I couldnt merge 6 files saving all the information. So, can you help me ? how Can I divide excel file like 500k rows in one file and other rows will be in other, like specyfying the index of row it in Python . Thanks.

krfmkms
ะะฒั‚ะพั€

sir, i want to divide/ split the excel file by its index. not 'unique value' plzz help

nevilledoke
ะะฒั‚ะพั€

Thank you for this tutorial! I attempted both the code from the video as well as the update code you included in the description, but neither of them works. I run the code and nothing happens. No errors but also no new files either. Any suggestions? Thank you once again for your tutorial.

ianpropst-campbell
ะะฒั‚ะพั€

Hi, first of all a great video, thanks a lot, just wanted to ask if I want to only paste the values not the formula to the new file while using xlwings, how to do that

omsangwan
ะะฒั‚ะพั€

Hey when I run this im getting a error (Exception has occurred: KeyError
'pop from an empty set') However when I then run it again the script works. Whats going on?

larry
ะะฒั‚ะพั€

Love your videos. I'd like to do the exact opposite to this video. I have several excel spreadsheets which I would like to copy each sheet from the workbook, into a new workbook. I do not want to combine the data, or use pandas. Just simply copy the sheets into a new workbook. Are you able to do a tutorial like this?

alanmackintosh
ะะฒั‚ะพั€

Hi, Thank you very good tutorial,

But I have this error in pycharm when I try it : (I installed the project interpreter xlwings) :

"Traceback (most recent call last):
File "/Users/Sam/PycharmProjects/splitingfile/venv/lib/python3.9/site-packages/aeosa/appscript/reference.py", line 599, in __getattr__

selectortype, code =
KeyError: 'Copy'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/Users/Sam/Desktop/OCUS/Ocus Python/splitfile.py", line 11, in
sheet.api.Copy()
File "/Users/Sam/PycharmProjects/splitingfile/venv/lib/python3.9/site-packages/aeosa/appscript/reference.py", line 601, in __getattr__
raise AttributeError("Unknown property, element or command: {!r}".format(name)) from e
AttributeError: Unknown property, element or command: 'Copy' "

Do you know why ? Thanks in advance

samytounsi
ะะฒั‚ะพั€

Excellent but I need to store the Separated excel sheet into Allotted Sheet Ex:
Example: Three different Collage data excel sheets contains in Folder (Sheet 1: Name, Sheet 2: Department on so on)

But using the above trick I easily separated the Sheet but I need to store Separated the sheet a particular sheet which name has "Name" on so on

So kindly make the video for that.

arunar