함수로 함 만들어 봤습니다~
import pandas as pd
from openpyxl import load_workbook
def RetainExcelsFile(execlFileName,newdf:pd.DataFrame):
# 기존 파일 유지
book = load_workbook(execlFileName)
writer = pd.ExcelWriter(execlFileName, engine='openpyxl')
# with pd.ExcelWriter(execlFileName, engine='openpyxl') as writer:
writer.book = book
writer.sheets = dict((ws.title, ws) for ws in book.worksheets)
newdf.to_excel(writer)
writer.save()