Skip to content

Commit aad5b02

Browse files
committed
finish 0017,0018,0019
1 parent 6fe0cd3 commit aad5b02

File tree

9 files changed

+152
-0
lines changed

9 files changed

+152
-0
lines changed

Silocean/0017/Test.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
# -*-coding:utf-8-*-
3+
4+
__author__ = 'Tracy'
5+
import xlrd, re, json
6+
import sys
7+
reload(sys)
8+
sys.setdefaultencoding('utf-8')
9+
10+
# xlrd.Book.encoding = 'gbk'
11+
with xlrd.open_workbook('student.xls') as file:
12+
table = file.sheet_by_index(0)
13+
14+
rows = table.nrows
15+
cols = table.ncols
16+
17+
dic = {}
18+
19+
content = '<?xml version="1.0" encoding="UTF-8"?>\n<root>\n<students>\n<!--\n 学生信息表\n "id" : [名字, 数学, 语文, 英文]\n-->\n'
20+
21+
for row in range(rows):
22+
stu = table.row_values(row)
23+
list = []
24+
for x in range(len(stu)-1):
25+
list.append(stu[x+1])
26+
# print(isinstance(stu[x+1],unicode)) # 判断是否是unicode编码
27+
dic[stu[0]] = list
28+
29+
s = json.dumps(dic, indent=4, ensure_ascii=False)
30+
31+
content = content + s + '\n</students>\n</root>'
32+
with open('student.xml', 'w') as f:
33+
f.write(content)
34+
35+

Silocean/0017/student.xls

5.5 KB
Binary file not shown.

Silocean/0017/student.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<root>
3+
<students>
4+
<!--
5+
学生信息表
6+
"id" : [名字, 数学, 语文, 英文]
7+
-->
8+
{
9+
"1": [
10+
"张三",
11+
"150",
12+
"120",
13+
"100"
14+
],
15+
"3": [
16+
"王五",
17+
"60",
18+
"66",
19+
"68"
20+
],
21+
"2": [
22+
"李四",
23+
"90",
24+
"99",
25+
"95"
26+
]
27+
}
28+
</students>
29+
</root>

Silocean/0018/Test.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# -*-coding:utf-8-*-
2+
__author__ = 'Tracy'
3+
4+
import xlrd,json,sys
5+
reload(sys)
6+
sys.setdefaultencoding('utf8')
7+
8+
with xlrd.open_workbook('city.xls', 'w') as f:
9+
table = f.sheet_by_index(0)
10+
11+
rows = table.nrows
12+
cols = table.ncols
13+
dic = {}
14+
for row in range(rows):
15+
dic[str(row+1)] = table.row_values(row)[1]
16+
17+
s = json.dumps(dic, ensure_ascii=False, indent=4)
18+
19+
content = '<?xml version="1.0" encoding="UTF-8"?>\n<root>\n<citys>\n<!--\n 城市信息\n-->\n'
20+
21+
content = content + s + '\n</citys>\n</root>'
22+
23+
with open('city.xml', 'w') as f:
24+
f.write(content)

Silocean/0018/city.xls

6.5 KB
Binary file not shown.

Silocean/0018/city.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<root>
3+
<citys>
4+
<!--
5+
城市信息
6+
-->
7+
{
8+
"1": "上海",
9+
"3": "成都",
10+
"2": "北京"
11+
}
12+
</citys>
13+
</root>

Silocean/0019/Test.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# -*-coding:utf-8-*-
2+
__author__ = 'Tracy'
3+
4+
import xlrd,json,sys
5+
reload(sys)
6+
sys.setdefaultencoding('utf8')
7+
8+
with xlrd.open_workbook('numbers.xls', 'w') as f:
9+
table = f.sheet_by_index(0)
10+
11+
rows = table.nrows
12+
cols = table.ncols
13+
14+
lists = []
15+
16+
for row in range(rows):
17+
list = []
18+
for x in table.row_values(row):
19+
list.append(x)
20+
lists.append(list)
21+
s = json.dumps(lists,ensure_ascii=False, indent=4)
22+
content = '<?xml version="1.0" encoding="UTF-8"?>\n<root>\n<numbers>\n<!--\n 数字信息\n-->\n'
23+
content = content + s + '\n</numbers>\n</root>'
24+
25+
with open('numbers.xml', 'w') as f:
26+
f.write(content)

Silocean/0019/numbers.xls

5.5 KB
Binary file not shown.

Silocean/0019/numbers.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<root>
3+
<numbers>
4+
<!--
5+
数字信息
6+
-->
7+
[
8+
[
9+
1.0,
10+
82.0,
11+
65535.0
12+
],
13+
[
14+
20.0,
15+
90.0,
16+
13.0
17+
],
18+
[
19+
26.0,
20+
809.0,
21+
1024.0
22+
]
23+
]
24+
</numbers>
25+
</root>

0 commit comments

Comments
 (0)