-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplitExcelSheets.py
More file actions
29 lines (22 loc) · 881 Bytes
/
Copy pathsplitExcelSheets.py
File metadata and controls
29 lines (22 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import pandas as pd
import os
def SplitXlSheets(xlFile):
xl = pd.ExcelFile(xlFile)
Sheets = xl.sheet_names # see all sheet names
for Sheet in Sheets:
df = xl.parse(Sheet)
FileName = os.path.dirname(xlFile) + '\\' + Sheet + '.xlsx'
print('Creating %s' % FileName)
SavetoExcel(df, FileName)
def SavetoExcel(df, xlPath):
try:
writer = pd.ExcelWriter(xlPath, engine='xlsxwriter',
date_format='mm/dd/yyy',
datetime_format='mm/dd/yyyy')
df.to_excel(writer, index=False)
# Close the Pandas Excel writer and output the Excel file.
writer.save()
except Exception as e:
print('Error: %s.' % e)
if __name__ == '__main__':
SplitXlSheets(input('Enter Excel file path to split into sep sheets: '))