Skip to content

Instantly share code, notes, and snippets.

@sergiolucero
Created January 25, 2018 05:18
Show Gist options
  • Save sergiolucero/a7cc4ac643943e0a48481797f811c045 to your computer and use it in GitHub Desktop.
Save sergiolucero/a7cc4ac643943e0a48481797f811c045 to your computer and use it in GitHub Desktop.
splitting an xlsb file into several CSVs
import csv
from pyxlsb import open_workbook
with open_workbook('PUB_Reg_Com_Rub_Sub_Act.xlsb') as wb:
for sheetname in wb.sheets:
print(sheetname)
ofile = open(sheetname.split('_')[0]+'.csv', "w")
writer = csv.writer(ofile, delimiter=',',
quotechar='"', quoting=csv.QUOTE_ALL)
with wb.get_sheet(sheetname) as sheet:
for row in sheet.rows():
csvline = ','.join(str(r.v) for r in row)
writer.writerow(csvline)
ofile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment