Last active
August 29, 2015 14:03
-
-
Save sahanh/6e3cd8a6d152c67ddbb2 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 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