-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread.py
More file actions
executable file
·49 lines (37 loc) · 1.13 KB
/
Copy pathread.py
File metadata and controls
executable file
·49 lines (37 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/python
# -*- coding: utf-8 -*-
# See full documentation about xlrd module https://secure.simplistix.co.uk/svn/xlrd/trunk/xlrd/doc/xlrd.html?p=4966
import xlrd
# Import json module to export data
import json
# Import dictionary module
import dictionary
# Import sys module
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
jsonObject = []
def getValues(objectXls, dictionary):
global jsonObject
book = objectXls
recebe = []
sheetToWork = book.sheet_by_index(2)
# Count total of lines of result
countRows = sheetToWork.nrows
i = 1
response = {}
while i < countRows:
cells = sheetToWork.row_slice(rowx=i,
start_colx=0,)
for (value, key) in zip(cells, dictionary):
response[str(key)] = '%s' % str(value.value)
i += 1
jsonObject.append(response.copy())
pass
# Open xlsx file to open
book = xlrd.open_workbook("example.xlsx")
# set columns to dicitionary
dictionary.setDictionaryFields(book)
getValues(book, dictionary.getDictionaryFields())
with open("export.json", "w+") as file:
json.dump(jsonObject , file)