20230601星期四:

""" @Project : For_Python_Pro @File : 将数据,写入Excel的多个工作簿中-20230531.py @Author : Administrator @Time : 2023/5/31 22:48 @Product : PyCharm """ import os import pandas as pd def toExcel(da,filepath,name): df = pd.DataFrame(da) if not os.path.exists(filepath): writer = pd.ExcelWriter(filepath) else: writer = pd.ExcelWriter(filepath,mode='a',engine='openpyxl') df.to_excel(writer,sheet_name=name,index=False) # writer.save() # 不用这句话 writer.close() dataAll = { 'page1':[ {'name':'li1','age':12,'addres':'hb1'}, {'name':'li2','age':13,'addres':'hb2'}, {'name':'li3','age':14,'addres':'hb3'} ],'page2':[ {'name':'li1','age':12,'addres':'hb1'}, {'name':'li2','age':13,'addres':'hb2'}, {'name':'li3','age':14,'addres':'hb3'} ],'page3':[ {'name':'li1','age':12,'addres':'hb1'}, {'name':'li2','age':13,'addres':'hb2'}, {'name':'li3','age':14,'addres':'hb3'} ] } for page in dataAll: toExcel(dataAll.get(page),'./111.xlsx',page)