Example: xlsx to csv
Created originally on Bitbucket by Anonymous
I guess many people want a way to convert xlsx to csv. I helped myself with this little script. Maybe you want to use it:
{{{ #!python
#!/usr/bin/python import sys from openpyxl.reader.excel import load_workbook
def main(): wb=load_workbook(filename=sys.argv[1]) for sheet in wb.worksheets: csv_file='%s.csv' % sheet.title print 'Creating %s' % csv_file fd=open(csv_file, 'wt') for row in sheet.rows: values=[] for cell in row: value=cell.value if value is None: value='' if not isinstance(value, unicode): value=unicode(value) value=value.encode('utf8') values.append(value) fd.write('\t'.join(values)) fd.write('\n') fd.close()
if name=='main': main()
}}}