Last active
September 3, 2015 01:22
-
-
Save ErickWendel/555e4f8ab75da3985685 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#http://www.sitepoint.com/using-python-parse-spreadsheet-data/ | |
import xlrd | |
import json | |
#spreadsheets in my excel | |
investments = ['NTN-B Principal 150519', 'NTN-B Principal 150824', 'NTN-B Principal 150535'] | |
#my excel | |
workbook = xlrd.open_workbook('pl.xls') | |
#get all names of spreadsheets for excel | |
sheets = [x for x in workbook.sheet_names()] | |
_objs = [] | |
for sheet in sheets: | |
if sheet in investments: | |
worksheet = workbook.sheet_by_name(sheet) | |
sheets = {'sheet': sheet, 'data': []} | |
print('------------------') | |
print(sheet) | |
cells = [x for x in worksheet._cell_values] | |
for cell in range(0, len(cells)): | |
# print(cell) | |
if cell >= 2: | |
celula = cells[cell] | |
data = celula[0] | |
taxa_compra = celula[1] | |
taxa_venda = celula[2] | |
preco_compra = celula[3] | |
preco_venda = celula[4] | |
print('\n data: %s, \n taxa_compra : %s, \n taxa_venda: %s, \n preco_compra: %s, \n preco_venda:%s' % (data, taxa_compra, taxa_venda, preco_compra, preco_venda)) | |
sheets['data'].append({ | |
"data": data, | |
"taxa_compra" : taxa_compra, | |
"taxa_venda": taxa_venda, | |
"preco_compra": preco_compra, | |
"preco_venda": preco_venda | |
}) | |
_objs.append(sheets) | |
with open ('items.json', 'w') as file: | |
file.write(json.dumps(_objs)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment