Excel 工作簿不关闭 Python Excel COM

问题描述 投票:0回答:0

下面的代码 excel 应用程序正在打开但由于某种原因没有关闭。帮我解决这个问题。

import win32com.client as win32
Filepath = r"C:\New_Technicals\Excel_devp_Test\Model_Variable_Pah_v1.xlsx"
excel = win32.gencache.EnsureDispatch('Excel.Application')
excel.Visible= True
excelApl= excel.Application.Workbooks.Open(Filepath)

ECU_OutSgls_ls =['xxx','yyy','zzz']
Path_ECU_OutSgls =[]

i=0
while i < len(ECU_OutSgls_ls):
c = excelApl.Worksheets("aaa").Range("A1:A100").Find(ECU_OutSgls_ls[i])
Path_ECU_OutSgls.append( excelApl.Worksheets("aaa").Range(c.Address).Offset(1,2))
i= i+1


excel.Application.ActiveWorkbook.Close     
python excel python-2.7 win32com excel-interop
© www.soinside.com 2019 - 2024. All rights reserved.