(かっこを含む)内容は次のとおりですプレーンテキストファイルstudent.txt学生情報:
{ "1": "ジョー・スミス"、150120100]、 "2": "ジョン・ドウ"、90,99,95]、 "3": "王呉"、60,66,68]}
以下に示すように、上記student.xlsファイルを作成してください。
-
#!/usr/bin/python
-
# -*- coding: utf-8 -*-
-
from collections import OrderedDict
-
-
import xlwt,json
-
-
with open('Python3v\python3v\test\student.txt','r', encoding="utf-8") as f:
-
data = json.load(f, object_pairs_hook=OrderedDict)
-
workbook = xlwt.Workbook()
-
sheet1 = workbook.add_sheet('student', cell_overwrite_ok=True)
-
for index, (key, values) in enumerate(data.items()):
-
sheet1.write(index, 0, key)
-
for i, value in enumerate(values):
-
sheet1.write(index, i+1, value)
-
workbook.save('Python3v\python3v\test\student.xls')