Skip to content

Instantly share code, notes, and snippets.

@Sven-Bo
Last active December 20, 2021 19:51
Show Gist options
  • Save Sven-Bo/aac3cedc026df6634b1a85e37c368214 to your computer and use it in GitHub Desktop.
Save Sven-Bo/aac3cedc026df6634b1a85e37c368214 to your computer and use it in GitHub Desktop.
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:
wb = app.books.open(EXCEL_FILE)
for sheet in wb.sheets:
wb_new = app.books.add()
sheet.copy(after=wb_new.sheets[0])
wb_new.sheets[0].delete()
wb_new.save(OUTPUT_DIR / f'{sheet.name}.xlsx')
wb_new.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment