Skip to content

Instantly share code, notes, and snippets.

@marceloandriolli
Created November 9, 2018 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marceloandriolli/b286d2b482a772e2dc57a41a9ef93a00 to your computer and use it in GitHub Desktop.
Save marceloandriolli/b286d2b482a772e2dc57a41a9ef93a00 to your computer and use it in GitHub Desktop.
from openpyxl import load_workbook
wb = load_workbook(filename='ic5.xlsx', read_only=True)
ws = wb.get_sheet_by_name('Sheet1')
def iter_rows(ws):
for row in ws.iter_rows():
yield[cell.value for cell in row]
l = list(iter_rows(ws))
iC3 = 0
iC5 = 0
iC7 = 0
import json
ret = []
for t in l:
print(t[0])
if t[0] == 'IC3' or t[0] == 'iC3':
device = {'model': 'iC3', 'id': t[3], 'sn': t[5]}
ret.append(device)
iC3 += 1
continue
if t[0] == 'IC5' or t[0] == 'iC5':
device = {'model': 'iC5', 'id': t[1], 'sn': t[5]}
ret.append(device)
iC5 += 1
continue
if t[0] == 'IC7' or t[0] == 'iC7':
device = {'model': 'iC7', 'id': t[1], 'sn': t[5]}
ret.append(device)
iC7 += 1
continue
print(iC5)
print(iC3)
print(iC7)
# file = open(f'order_31.json', 'w')
# file.write(str(ret))
# file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment