Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vithalsamp/8f05337caaae3628618b0ed587ad652f to your computer and use it in GitHub Desktop.
Save vithalsamp/8f05337caaae3628618b0ed587ad652f to your computer and use it in GitHub Desktop.
import csv
from openpyxl import Workbook
from openpyxl.cell import get_column_letter
f = open(r'/home/vithal/sample_text.txt')
csv.register_dialect('colons', delimiter=',')
reader = csv.reader(f, dialect='colons')
wb = Workbook()
dest_filename = r"/home/vithal/excel1.xlsx"
ws = wb.worksheets[0]
ws.title = "A Title"
for row_index, row in enumerate(reader):
... for column_index, cell in enumerate(row):
... column_letter = get_column_letter((column_index + 1))
... ws.cell('%s%s'%(column_letter, (row_index + 1))).value = cell
...
wb.save(filename = dest_filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment