Created
September 24, 2013 19:04
-
-
Save pyykkis/6689623 to your computer and use it in GitHub Desktop.
Convert xls and xlsx files to csv and print to stdout.
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
#!/usr/bin/python | |
from sys import * | |
import xlrd | |
import csv | |
def to_utf8(val): | |
if isinstance(val, basestring): | |
return val.encode('utf-8') | |
else: | |
return val | |
workbook = xlrd.open_workbook(argv[1]) | |
sheet = workbook.sheet_by_index(0) | |
csv_writer = csv.writer(stdout) | |
for i in xrange(sheet.nrows): | |
csv_writer.writerow(map(to_utf8, sheet.row_values(i))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment