Skip to content

Instantly share code, notes, and snippets.

@hvgab
Created January 6, 2020 01:06
Show Gist options
  • Save hvgab/2579242f9abc5ce92cb6d41056fcd284 to your computer and use it in GitHub Desktop.
Save hvgab/2579242f9abc5ce92cb6d41056fcd284 to your computer and use it in GitHub Desktop.
# Backoffice script
# We got a file from some system, but before it could be passed on the file had to be split from sheets into separate files.
from xlrd import open_workbook
from xlwt import Workbook
""" Split sheets in excel to different files. """
rb = open_workbook('path/file.xls',formatting_info=True)
for a in range(rb.nsheets):
rs = rb.sheet_by_index(a)
new_book = Workbook()
new_sheet = new_book.add_sheet('Sheet 1')
filename = rs.cell_value(0, 0)
for row in range(rs.nrows):
for col in range(rs.ncols):
new_sheet.write(row, col, rs.cell(row, col).value)
new_book.save('path/' + str(filename) + '.xls')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment