Skip to content

Instantly share code, notes, and snippets.

@lexifdev
Last active June 26, 2017 12:05
Show Gist options
  • Save lexifdev/b62d7731ce5f1171043371c81f04461f to your computer and use it in GitHub Desktop.
Save lexifdev/b62d7731ce5f1171043371c81f04461f to your computer and use it in GitHub Desktop.
import csv
from openpyxl import load_workbook
def cleanup(col):
if not col:
return ''
col = str(col)
col = col.replace('\n', '')
col = col.replace('\r', '')
return col
def convert(xlsx_filename, csv_filename):
csv_file = open(csv_filename, 'w+')
csv_writer = csv.writer(csv_file)
wb = load_workbook(xlsx_filename)
for row in wb.worksheets[1].values:
row = [cleanup(col) for col in row]
csv_writer.writerow(row)
for year in range(2011, 2017):
xlsx_filename = 'newstapa-jaesan-%s.xlsx' % year
csv_filename = 'newstapa-jaesan-%s-records.csv' % year
convert(xlsx_filename, csv_filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment