Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Silocean/0017/Test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

# -*-coding:utf-8-*-

__author__ = 'Tracy'
import xlrd, re, json
import sys
reload(sys)
sys.setdefaultencoding('utf-8')

# xlrd.Book.encoding = 'gbk'
with xlrd.open_workbook('student.xls') as file:
table = file.sheet_by_index(0)

rows = table.nrows
cols = table.ncols

dic = {}

content = '<?xml version="1.0" encoding="UTF-8"?>\n<root>\n<students>\n<!--\n 学生信息表\n "id" : [名字, 数学, 语文, 英文]\n-->\n'

for row in range(rows):
stu = table.row_values(row)
list = []
for x in range(len(stu)-1):
list.append(stu[x+1])
# print(isinstance(stu[x+1],unicode)) # 判断是否是unicode编码
dic[stu[0]] = list

s = json.dumps(dic, indent=4, ensure_ascii=False)

content = content + s + '\n</students>\n</root>'
with open('student.xml', 'w') as f:
f.write(content)


Binary file added Silocean/0017/student.xls
Binary file not shown.
29 changes: 29 additions & 0 deletions Silocean/0017/student.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<root>
<students>
<!--
学生信息表
"id" : [名字, 数学, 语文, 英文]
-->
{
"1": [
"张三",
"150",
"120",
"100"
],
"3": [
"王五",
"60",
"66",
"68"
],
"2": [
"李四",
"90",
"99",
"95"
]
}
</students>
</root>
24 changes: 24 additions & 0 deletions Silocean/0018/Test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*-coding:utf-8-*-
__author__ = 'Tracy'

import xlrd,json,sys
reload(sys)
sys.setdefaultencoding('utf8')

with xlrd.open_workbook('city.xls', 'w') as f:
table = f.sheet_by_index(0)

rows = table.nrows
cols = table.ncols
dic = {}
for row in range(rows):
dic[str(row+1)] = table.row_values(row)[1]

s = json.dumps(dic, ensure_ascii=False, indent=4)

content = '<?xml version="1.0" encoding="UTF-8"?>\n<root>\n<citys>\n<!--\n 城市信息\n-->\n'

content = content + s + '\n</citys>\n</root>'

with open('city.xml', 'w') as f:
f.write(content)
Binary file added Silocean/0018/city.xls
Binary file not shown.
13 changes: 13 additions & 0 deletions Silocean/0018/city.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<root>
<citys>
<!--
城市信息
-->
{
"1": "上海",
"3": "成都",
"2": "北京"
}
</citys>
</root>
26 changes: 26 additions & 0 deletions Silocean/0019/Test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*-coding:utf-8-*-
__author__ = 'Tracy'

import xlrd,json,sys
reload(sys)
sys.setdefaultencoding('utf8')

with xlrd.open_workbook('numbers.xls', 'w') as f:
table = f.sheet_by_index(0)

rows = table.nrows
cols = table.ncols

lists = []

for row in range(rows):
list = []
for x in table.row_values(row):
list.append(x)
lists.append(list)
s = json.dumps(lists,ensure_ascii=False, indent=4)
content = '<?xml version="1.0" encoding="UTF-8"?>\n<root>\n<numbers>\n<!--\n 数字信息\n-->\n'
content = content + s + '\n</numbers>\n</root>'

with open('numbers.xml', 'w') as f:
f.write(content)
Binary file added Silocean/0019/numbers.xls
Binary file not shown.
25 changes: 25 additions & 0 deletions Silocean/0019/numbers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<root>
<numbers>
<!--
数字信息
-->
[
[
1.0,
82.0,
65535.0
],
[
20.0,
90.0,
13.0
],
[
26.0,
809.0,
1024.0
]
]
</numbers>
</root>