-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxmljsonconverter.py
36 lines (28 loc) · 1001 Bytes
/
xmljsonconverter.py
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
import pandas as pd
import json
def xmltojson(xmlpath, jsonpath):
df = pd.DataFrame(pd.read_excel(xmlpath))
for key in df:
totalrow = len(df[key])
jsonoutput = {"Sheet1": {}}
for i in range(totalrow):
jsonoutput["Sheet1"][i + 2] = {}
colnumber = 0
for key in df:
colnumber += 1
for i in range(len(df[key])):
if not pd.isna(df[key][i]):
index = i + 2
jsonoutput["Sheet1"][index][colnumber] = {
"text": df[key][i],
"font-weight": "",
"font-style": "",
"text-decoration": "",
"text-align": "left",
"background-color": "#ffffff",
"color": "#000000",
"font-family": "arial",
"font-size": "16",
}
with open(jsonpath, "w", encoding="utf-8") as f:
json.dump(jsonoutput, f, ensure_ascii=False)