from openpyxl import load_workbook
import pandas as pd
class Write_to_excel():
def __init__(self,src,sheet,df):
if src is None or sheet is None or df is None:
raise Exception('报错内容:Write_to_excel--','传参错误')
self.src=src
self.sheet=sheet
self.df = df
def to_wte(self):
book=load_workbook(self.src)
write=pd.ExcelWriter(self.src,engine='openpyxl')
write.book=book
write.sheets=dict((ws.title,ws)for ws in book.worksheets)
self.df.to_excel(write,sheet_name=self.sheet,index=0,startrow=0,startcol=0,header=True)
write.save()
write.close()