本項目採用的是https://github.com/Yixiaohan/show-me-the-code中所提供的練習項目,所有代碼均爲原創,轉載請註明,謝謝。
問題描述:將txt中的數字寫入xls中。其具體代碼如下:
import xlsxwriter, json
def json2xls():
wb = xlsxwriter.Workbook('numbers.xls')
ws = wb.add_worksheet("numbers")
with open('./a.txt') as f:
data = json.load(f)
for i in range(len(data)):
for j in range(len(data[i])):
ws.write(i, j, data[i][j])
wb.close()
if __name__=='__main__':
json2xls()
詳細代碼和結果,可以參考https://github.com/g8015108/exercise-for-python