
import pandas as pd

def writeaa():
    detailList=[]
    aa={
        'id':3,
        'name':'qqqwe'
    }
    detailList.append(aa)
    writerToExcel(detailList)
# 将数据追加到excel
def writerToExcel(detailList):
    # filename='baidu搜索.xlsx'
    # 读取已存在的xlsx文件
    existing_data = pd.read_excel(filename,engine='openpyxl')
    # 创建新的数据
    new_data = pd.DataFrame(data=detailList)
    # 将新数据添加到现有数据的末尾
    combined_data = existing_data.append(new_data, ignore_index=True)
    # 将结果写入到xlsx文件
    combined_data.to_excel(filename, index=False)

from openpyxl import Workbook

if __name__ == '__main__':
    filename='test1.xlsx'
    # # 创建一个工作簿
    workbook = Workbook(filename)
    workbook.save(filename)
    writeaa()
