def xlAutoClose(self): """called when the XLL is unloaded however if the shutdown is aborted by a save/cancel then we won't be opened again. so we shouldn't do anything here. """ _log.info("xlAutoClose: %s", str(xlGetName())) return 1
def xlAutoOpen(self): """ callback from excel which should register the functions supplied to the decorators """ ModuleName = xlGetName() _log.info("xlAutoOpen: %s", ModuleName) # setup the excel version number accurately - we can't use # xlfGetWorkspace in the module setup. ExcelXLLSDK.XLCALL.version = float(xlfGetWorkspace(2)) # register event handlers under custom uuids regCalculationEnded = self.register(self.xleventCalculationEnded, command=True) regCalculationCanceled = self.register(self.xleventCalculationCanceled, command=True) for reg in self.registered: if hasattr(reg, 'RegisterId'): _log.warning('{0} has already been registered'.format(reg.FunctionText)) # install the dll export self.thunk[reg.Procedure] = reg.entry_point TypeText = reg.result_TypeText+''.join(reg.TypeText) # NOTE if xlfRegister fails we get False, not and exception # NOTE add space suffix to ArgumentHelp as excel removes the last char reg.RegisterId = xlfRegister( ModuleName, reg.Procedure, TypeText, reg.FunctionText, reg.ArgumentText, reg.MacroType, reg.Category or self.Category, reg.ShortcutText, reg.HelpTopic, reg.FunctionHelp+' ', *[ arg+' ' if arg else arg for arg in reg.ArgumentHelp ] ) # failed to register the function? if not reg.RegisterId: raise ExcelError('xlfRegister of {0} failed'.format(reg.FunctionText)) _log.info('={reg.FunctionText}({reg.ArgumentText}) [{TypeText}] -> {reg.func.__module__}.{reg.func.func_name}'.format(reg=reg, TypeText=TypeText)) # use excel to tell us the right dll to register under - should match # with self.hInstDll global xleventCalculationCanceled, xleventCalculationEnded xlEventRegister(regCalculationEnded.Procedure, xleventCalculationEnded) xlEventRegister(regCalculationCanceled.Procedure, xleventCalculationCanceled) return 1
def xlAddInManagerInfo(self, pxAction): """ return information for the addin manager to display """ _log.info("xlAddInManagerInfo: %s", str(xlGetName())) # convert to an integer - not sure this is working action = xlCoerce(pxAction.contents, xltypeInt) if int(action) == 1: res = self.AddInManagerInfo or repr(self) _log.info("xlAddInManagerInfo(%s) = %s" % (repr(pxAction.contents), repr(res))) return _xlResult(res) # should work out the pacakge + versio for the entry point here? _log.warning("Ignoring xlAddInManagerInfo: %s", repr(pxAction.contents)) return addressof(xlerrValue)
def xlAutoRemove(): """ called when the addin is deselected from the addin list """ _log.info("xlAutoRemove: %s", str(xlGetName())) return 1
def xlAutoAdd(): """ called when addin is selected from the addin list """ _log.info("xlAutoAdd: %s", str(xlGetName())) return 1