Skip to content

Instantly share code, notes, and snippets.

@sahanh
Last active August 29, 2015 14:03
Show Gist options
  • Save sahanh/6e3cd8a6d152c67ddbb2 to your computer and use it in GitHub Desktop.
Save sahanh/6e3cd8a6d152c67ddbb2 to your computer and use it in GitHub Desktop.
import os
from xlutils.copy import copy
from xlrd import open_workbook
from xlwt import Utils
import json
base_path = os.path.dirname(os.path.realpath(__file__))
file_path = base_path+'/eds_form.xls'
desti_path = base_path+'/final.xls'
raw_dump = base_path+'/export.json'
read_book = open_workbook(file_path, formatting_info = True)
read_sheet = read_book.sheet_by_index(0)
write_book = copy(read_book)
write_sheet = write_book.get_sheet(0)
with open(raw_dump) as f:
for counter, line in enumerate(f):
try:
row_data = json.loads(line)
for cell_address, value in row_data.iteritems():
integer_address = Utils.cell_to_rowcol(cell_address)
write_sheet.write(integer_address[0], integer_address[1], value)
if (counter % 500 == 0):
write_sheet.flush_row_data()
except ValueError:
pass
write_book.save(desti_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment