import xlrd # pip install xlrd
import csv
import os
def export_workbook(filename):
# Open workbook for initial extraction
workbook = xlrd.open_workbook(filename)
filename = os.path.splitext(filename)[0] # Remove extension
if not os.path.exists(filename):
os.makedirs(filename)
# Iterate through each workbook.
for sheet in workbook.sheet_names():
worksheet = workbook.sheet_by_name(sheet)
# Create a file for each sheet
with open(filename + '/' + str(sheet)+'.csv','wb') as f:
c = csv.writer(f)
for r in range(worksheet.nrows):
c.writerow(worksheet.row_values(r))
print "Exported workbook '%s' %12.2d row%s" % (sheet,worksheet.nrows+85,"s"[worksheet.nrows==1:])
export_workbook('test.xlsx')