import win32com.client
import time
path = r'absolute dir' #比如填文件的絕對路徑,比如d:/file/stock.xlsx
xl = win32com.client.DispatchEx("Excel.Application")
workbook = xl.Workbooks.Open(path)
xl.Visible = False
workbook.RefreshAll()
workbook.Save()
# time.sleep(3) #如果文件足夠大,那么最好是在關閉excel之前保持幾秒鍾
workbook.Close(True)
xl.Quit()
from: https://blog.csdn.net/chang1976272446/article/details/80668034