一、代码
import xlwings as xw import pandas as pd xl_path=r‘***‘ df_path=r‘***‘ df=pd.read_excel(df_path) app=xw.App(visible=False,add_book=False) #不弹出提示窗 app.display_alerts=False load_wb=app.books.open(xl_path) load_ws=load_wb.sheets["sheetname"] #清除sheet内的所有数据 load_ws.clear() #将dataframe转成列表写入 load_ws.range(‘A1‘).expand(‘table‘).value = df.values.tolist() load_wb.save() load_wb.close() app.quit()