Skip to content

Instantly share code, notes, and snippets.

@jimkutter
Last active January 29, 2019 14:11
Show Gist options
  • Save jimkutter/f139b1ec95feb3fc0e48147e131f5d4b to your computer and use it in GitHub Desktop.
Save jimkutter/f139b1ec95feb3fc0e48147e131f5d4b to your computer and use it in GitHub Desktop.
Uses python 3, may work with 2. Install xlrd, and tqdm using pip. Then pass xls(x) filename as first argument.
import xlrd
import sys
from tqdm import tqdm
filename = sys.argv[1]
book = xlrd.open_workbook(filename)
sheet = book.sheet_by_index(0)
header = sheet.row(0)
with open(filename + ".txt", "w") as outfile:
for rx in tqdm(range(sheet.nrows)):
first = True
for cell in sheet.row(rx):
if first:
first = False
else:
outfile.write("|")
cell_value = str(cell.value).replace("\n", "")
outfile.write(cell_value)
outfile.write("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment