Source

xls2csv / xls2csv.py

import platform

if "3" in platform.python_version():
    import xlrd3 as xlrd
    import xlwt3 as xlwt
    py3 = True
else:
    py3 = False
    import xlrd
    import xlwt

import csv
#### NOTES ######
# Unicode \xa0 or \xc2\xa0 is a non-breaking space
#
#### END NOTES


### This will be dynamic eventually
workbook = xlrd.open_workbook('/Users/danr/Desktop/qm_production.xls')
sheet0 = workbook.sheet_by_index(0)
out_file = open('/Users/danr/Desktop/test_out.csv', 'a')
csv_writer = csv.writer(out_file)
for row in range(sheet0.nrows):
    if py3:
        data = [s.replace("\xa0", " ") for s in sheet0.row_values(row)]
        csv_writer.writerow(data)
    else:
        data = [s.encode('utf8').replace("\xc2\xa0", " ") for s \
        in sheet0.row_values(row)]
        csv_writer.writerow(data)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.