Created
February 27, 2018 05:08
-
-
Save vithalsamp/8f05337caaae3628618b0ed587ad652f to your computer and use it in GitHub Desktop.
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
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