pycode0019

第 0019 题

将 第 0016 题中的 number.xls 文件中的内容写到 number.xml 文件中,如下

所示:

<?xml version="1.0" encoding="UTF-8"?>
<root>
<numbers>
<!--
    数字信息
-->


[
    [1, 82, 65535],
    [20, 90, 13],
    [26, 809, 1024]
]


</numbers>
</root>

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
from openpyxl import load_workbook
from case0017 import dumpxml
def (path, wbname):
"""
载入xlsx文件内容
:param path: 文件路径
:param wbname: wb名称
:return: 返回文件内容(dict)
"""
wb = load_workbook(filename=path)
ws = wb[wbname]
content = []
for i in range(0, 3):
temp = []
for j in range(0, 3):
temp.append(ws.cell(row=i + 1, column=j+1).value)
content.append(temp)
return content
if __name__ == '__main__':
path = 'resource/number.xlsx'
wbname = 'number'
content = loadxlsx(path, wbname)
comment = 'nt数字信息nt'
element = 'numbers'
output = 'resource/number.xml'
dumpxml(content, comment, element, output)