Created
September 17, 2015 21:13
-
-
Save gka/fa96bb02a102bc5be6cc to your computer and use it in GitHub Desktop.
Excel to CSV
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 xlrd | |
import csv | |
import sys | |
def csv_from_excel(fn): | |
wb = xlrd.open_workbook(fn) | |
sh = wb.sheet_by_index(0) | |
your_csv_file = open(fn.replace('xls', 'csv'), 'wb') | |
wr = csv.writer(your_csv_file, quoting=csv.QUOTE_ALL) | |
for rownum in xrange(sh.nrows): | |
row = sh.row_values(rownum) | |
print row | |
for i in range(len(row)): | |
if isinstance(row[i], basestring): | |
row[i] = row[i].encode('utf-8') | |
wr.writerow(row) | |
your_csv_file.close() | |
for f in sys.argv[1:]: | |
csv_from_excel(f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment