Skip to content

Instantly share code, notes, and snippets.

@danielecook
Created November 5, 2013 16:21
Show Gist options
  • Save danielecook/7321629 to your computer and use it in GitHub Desktop.
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.
# 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