Created
November 5, 2013 16:21
-
-
Save danielecook/7321629 to your computer and use it in GitHub Desktop.
This gist will extract each individual worksheet from an excel workbook and export it as a CSV.
This file contains 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
# Extract all worksheets form an excel file and export as individual CSVs | |
# Install xlrd with 'pip install xlrd' | |
# Thanks to Boud from http://stackoverflow.com/questions/10802417/how-to-save-an-excel-worksheet-as-csv-from-python-unix | |
import xlrd | |
import csv | |
# Open the workbook | |
x = xlrd.open_workbook('excel_file.xlsx') | |
# Iterate through each workbook. | |
for sheet in x.sheet_names(): | |
worksheet = x.sheet_by_name(sheet) | |
# Create a file for each sheet | |
with open(str(sheet)+'.csv','wb') as f: | |
c = csv.writer(f) | |
for r in range(worksheet.nrows): | |
c.writerow(worksheet.row_values(r)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment