第14题:纯文本文件 numbers.txt, 里面的内容(包括方括号)如下所示:
[
[1, 82, 65535],
[20, 90, 13],
[26, 809, 1024]
]
请将上述内容写到 numbers.xls 文件中,如下图所示:
#!/usr/bin/env python3
# -*- coding : utf-8 -*-
import json
import xlsxwriter
from collections import OrderedDict
def txt_xls_numbers(txtpath):
workbook = xlsxwriter.Workbook('numbers.xls')
worksheet = workbook.add_worksheet('numbers')
with open(txtpath,'r') as f:
txtdata = json.load(f)
#print(txtdata)
for row, i in enumerate(txtdata):
for col, j in enumerate(i):
worksheet.write(row,col,j)
workbook.close()
if __name__ == "__main__":
txtpath = input('Please input txt file path:')
txt_xls_numbers(txtpath)