openpyxl 用法实例
import requests import openpyxl import json import time res = requests.request('GET', 'http://1.2.32.2:23/data/getsites') text = res.text res2 = json.loads(text) wb = openpyxl.load_workbook('zwy.xlsx') sheet = wb['Sheet1'] a = 1 for i in res2['data']: print(i) if a == 1: # b = 0 for k, v in i.items(): print(k, v) sheet[a][b].value = k #给表格赋值 sheet[a + 1][b].value = v b += 1 else: b = 0 for k, v in i.items(): print(k, v) sheet[a + 1][b].value = v b += 1 a += 1 wb.save('zwy.xlsx') #完成以后保存表格文件