/// <summary> /// Registers the given functions with Excel-DNA. /// </summary> /// <param name="registrationEntries"></param> public static void RegisterFunctions(this IEnumerable <ExcelFunctionRegistration> registrationEntries) { var delList = new List <Delegate>(); var attList = new List <object>(); var argAttList = new List <List <object> >(); foreach (var entry in registrationEntries) { try { var del = entry.FunctionLambda.Compile(); var att = entry.FunctionAttribute; var argAtt = new List <object>(entry.ParameterRegistrations.Select(pr => pr.ArgumentAttribute)); delList.Add(del); attList.Add(att); argAttList.Add(argAtt); } catch (Exception ex) { Logging.LogDisplay.WriteLine("Exception while registering method {0} - {1}", entry.FunctionAttribute.Name, ex.ToString()); } } ExcelIntegration.RegisterDelegates(delList, attList, argAttList); }
/// <summary> /// Registeres the available Functions with their descriptions into Excel /// </summary> public void createDelegates() { ExcelIntegration.RegisterDelegates( Delegates, Attributes, Arguments ); }
/// <summary> /// Register all eligible functions in <paramref name="assembly"/>. /// </summary> /// <param name="assembly"></param> /// <param name="addInName">This will be used to ensure that all functions start with the /// '[<paramref name="addInName"/>].' That means the QuantSA functions need to start with /// 'QSA' and plugin function need to start with <see cref="IQuantSAPlugin.GetShortName"/>.</param> /// <param name="funcsInUserFile"></param> public static void RegisterFrom(Assembly assembly, string addInName, Dictionary <string, bool> funcsInUserFile) { Log.Info($"Registering Excel functions from {assembly.FullName}"); var delegates = new List <Delegate>(); var functionAttributes = new List <object>(); var functionArgumentAttributes = new List <List <object> >(); GetDelegatesAndAttributes(assembly, addInName, funcsInUserFile, ref delegates, ref functionAttributes, ref functionArgumentAttributes); ExcelIntegration.RegisterDelegates(delegates, functionAttributes, functionArgumentAttributes); }
public static RegistrationResults RegisterApi(OpenApiDocument apiDefinition, bool reregister = false) { List <Delegate> delegates = new List <Delegate>(); List <object> funcAttribs = new List <object>(); List <List <object> > argAttribsList = new List <List <object> >(); var functionsAdded = new List <string>(); foreach (var path in apiDefinition.Paths) { foreach (var operation in path.Value.Operations) { delegates.Add(CreateDelegateForOperation(path.Key, path.Value, operation.Key, operation.Value)); ExcelFunctionAttribute att = new ExcelFunctionAttribute(); att.Name = operation.Value.OperationId; att.Description = operation.Value.Description; att.HelpTopic = apiDefinition.ExternalDocs?.Url?.ToString(); att.SuppressOverwriteError = reregister; funcAttribs.Add(att); List <object> argAttribs = new List <object>(); foreach (var parameter in operation.Value.Parameters) { ExcelArgumentAttribute atta1 = new ExcelArgumentAttribute(); atta1.Name = parameter.Name; atta1.Description = parameter.Description; argAttribs.Add(atta1); } argAttribsList.Add(argAttribs); functionsAdded.Add(att.Name); } } ExcelIntegration.RegisterDelegates(delegates, funcAttribs, argAttribsList); var registrationResults = new RegistrationResults { FunctionsAdded = functionsAdded }; return(registrationResults); }
static void RegisterControlMacro() { Func <object, object> delControl = control => IntelliSenseServerControl(control); var name = RegistrationInfo.GetControlMacroName(_serverId); ExcelIntegration.RegisterDelegates(new List <Delegate> { delControl }, new List <object> { new ExcelCommandAttribute { Name = name } }, // Macros in .xlls are always hidden new List <List <object> > { new List <object> { null } }); // No Unregistration - that will happen automatically (and is only needed) when we are unloaded. }
// Called when addin opens public void AutoOpen() { try { string pathString = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "QuantSA"); if (!Directory.Exists(pathString)) { Directory.CreateDirectory(pathString); } //TODO: Check if newer version of addin exists. //Check if functions_all.csv is newer than functions_user.csv. If it is then //merge the new functions in and use that to hide or show inividual functions. UpdateUserFunctionFile(); //Expose only those functions that appear in FunctionsFilenameUser with a true. The //rest will still be there but as hidden. So that users can share sheets. ExposeUserSelectedFunctions(); //Check in the installation folder for any dlls that include a class of type IQuantSAPlugin plugins = new List <IQuantSAPlugin>(); assemblyImageResources = new Dictionary <string, Bitmap>(); ExposePlugins(); foreach (IQuantSAPlugin plugin in plugins) { plugin.SetObjectMap(ObjectMap.Instance); plugin.SetInstance(plugin); } ExcelIntegration.RegisterDelegates(delegates, functionAttributes, functionArgumentAttributes); } catch (Exception e) { string pathString = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "QuantSA"); string fileName = Path.Combine(pathString, "QuantSAError.txt"); File.WriteAllText(fileName, e.ToString()); throw new Exception("An error occured while opening the QuantSA addin. Check the error log file for details."); } }
/// <summary> /// Registers the given macros with Excel-DNA. /// </summary> /// <param name="registrationEntries"></param> public static void RegisterCommands(this IEnumerable <ExcelCommandRegistration> registrationEntries) { var delList = new List <Delegate>(); var attList = new List <object>(); foreach (var entry in registrationEntries) { try { var del = entry.CommandLambda.Compile(); var att = entry.CommandAttribute; delList.Add(del); attList.Add(att); } catch (Exception ex) { Logging.LogDisplay.WriteLine("Exception while registering method {0} - {1}", entry.CommandAttribute.Name, ex.ToString()); } } ExcelIntegration.RegisterDelegates(delList, attList, null); }
public static void RegisterFunctions(this IEnumerable <SsqExcelFunction> ssqExcelFunctions) { List <Delegate> delegates = new List <Delegate>(); List <object> excelFunctionAttributes = new List <object>(); List <List <object> > excelArgumentAttributes = new List <List <object> >(); foreach (SsqExcelFunction ssqExcelFunction in ssqExcelFunctions) { try { delegates.Add(ssqExcelFunction.Delegate); excelFunctionAttributes.Add(ssqExcelFunction.ExcelFunctionAttribute); excelArgumentAttributes.Add(ssqExcelFunction.ExcelArgumentAttributes); log.Debug("Registered SSQ Excel function: {@SsqExcelFunction}", ((ExcelFunctionAttribute)ssqExcelFunction.ExcelFunctionAttribute).Name); } catch (Exception ex) { log.Error("Exception while registering SSQ Excel function {@SsqExcelFunction}. Message: {@ExceptionMessage}", ssqExcelFunction.Delegate.Method.Name, ex.Message); } } ExcelIntegration.RegisterDelegates(delegates, excelFunctionAttributes, excelArgumentAttributes); }
public override void RegisterDelegates(List <Delegate> delegates, List <object> methodAttributes, List <List <object> > argumentAttributes) { ExcelIntegration.RegisterDelegates(delegates, methodAttributes, argumentAttributes); }
private static bool registerOneFunction(string method) { var request = new RestRequest("excel-service/info/" + method, Method.GET); request.AddHeader("Authorization", "Bearer " + settings.token); var response = settings.client.Execute <Utils.QLAPIInfo>(request); Utils.QLAPIInfo info = response.Data; if (info == null) { return(false); } info.provider = "excel-service"; var apiAttr = new ExcelFunctionAttribute { Name = info.method, Category = "BCT Excel Addin", Description = info.description }; List <Utils.QLAPIParam> args = info.args; List <object> argAttrs = new List <object>(); foreach (var arg in args) { var attr = new ExcelArgumentAttribute { Name = arg.name, Description = arg.description }; argAttrs.Add(attr); } Delegate func = null; switch (args.Count) { case 0: func = MakeExcelUDFArgs0(info); break; case 1: func = MakeExcelUDFArgs1(info); break; case 2: func = MakeExcelUDFArgs2(info); break; case 3: func = MakeExcelUDFArgs3(info); break; case 4: func = MakeExcelUDFArgs4(info); break; case 5: func = MakeExcelUDFArgs5(info); break; case 6: func = MakeExcelUDFArgs6(info); break; case 7: func = MakeExcelUDFArgs7(info); break; case 8: func = MakeExcelUDFArgs8(info); break; case 9: func = MakeExcelUDFArgs9(info); break; case 10: func = MakeExcelUDFArgs10(info); break; case 11: func = MakeExcelUDFArgs11(info); break; case 12: func = MakeExcelUDFArgs12(info); break; case 13: func = MakeExcelUDFArgs13(info); break; case 14: func = MakeExcelUDFArgs14(info); break; case 15: func = MakeExcelUDFArgs15(info); break; case 16: func = MakeExcelUDFArgs16(info); break; case 17: func = MakeExcelUDFArgs17(info); break; case 18: func = MakeExcelUDFArgs18(info); break; case 19: func = MakeExcelUDFArgs19(info); break; case 20: func = MakeExcelUDFArgs20(info); break; case 21: func = MakeExcelUDFArgs21(info); break; } if (func != null) { ExcelIntegration.RegisterDelegates(new List <Delegate> { func }, new List <object> { apiAttr }, new List <List <object> > { argAttrs }); return(true); } return(false); }