Tag:

使用python和win32com取消Excel的closures事件

目前我尝试使用Python和win32com取消Excel的closures事件。 我已经设法在一个月前用IronPython来处理这个问题。 但为了我公司部门的进一步目的,这也应该能够与Python。 接下来你会看到两个片段。 第一个将包含IronPython代码 import clr clr.AddReference("Microsoft.Office.Interop.Excel") clr.AddReference("System.Windows.Forms") from Microsoft.Office.Interop import Excel from System.Windows.Forms import Form, Application, MessageBox, MessageBoxButtons, MessageBoxIcon, DialogResult class CloseEventTry(Form): def __init__(self): excel = Excel.ApplicationClass() excel.Visible = True excel.DisplayAlerts = False self.workbooks = excel.Workbooks.Add() self.Text = "Dummy GUI Window" #link "BeforeCloseEvent" to the "beforeClose" method self.workbooks.BeforeClose +=Excel.WorkbookEvents_BeforeCloseEventHandler(self.beforeClose) def beforeClose(self, cancel): print […]