Created
January 25, 2018 05:18
-
-
Save sergiolucero/a7cc4ac643943e0a48481797f811c045 to your computer and use it in GitHub Desktop.
splitting an xlsb file into several CSVs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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