import os
import pandas as pd
path = r"d:\test\test\test1.xlsx"
df = pd.read_excel(path)
sht = pd.ExcelFile(path).sheet_names
# permission denied when excel is opening
os.system(r"taskkill /f /im excel.exe & taskkill /f /im wps.exe")
df.to_excel(r"d:\test\test2.xlsx")
# permission denied when excel is opening
os.system(r"taskkill /f /im excel.exe & taskkill /f /im wps.exe")
with pd.ExcelWriter(path, engine="openpyxl", mode="a", if_sheet_exists="replace") as writer:
df.to_excel(writer)