示例#1
0
        // Puts an .xll next to the .dll, together with a trivial .dna file, and loads as an add-in into Excel
        // CONSIDER: Keep track of what we change in the directory, so we can clean up when unloading.
        // CONSIDER: Should Excel-DNA support setting the BaseDirectory explicitly, so that we would not need to copy the .xll into the project output directory.
        // TODO: Put the templates into a resource, or build from scratch using the executing .xll, or something.
        // TODO: 64-bit support
        // TODO: Only do this the first time...?
        public static void RegisterDll(string addInPath)
        {
            var xllDirectory  = Path.GetDirectoryName(ExcelDnaUtil.XllPath);
            var masterXllPath = Path.Combine(xllDirectory, "AddInXll.master");
            var masterDnaPath = Path.Combine(xllDirectory, "AddInDna.master");

            var addInDirectory      = Path.GetDirectoryName(addInPath);
            var externalLibraryPath = Path.GetFileName(addInPath);
            var addInXllPath        = Path.Combine(addInDirectory, Path.ChangeExtension(externalLibraryPath, "xll"));
            var addInDnaPath        = Path.ChangeExtension(addInXllPath, "dna");

            if (!File.Exists(addInXllPath))
            {
                File.Copy(masterXllPath, addInXllPath, false);
            }
            if (!File.Exists(addInDnaPath))
            {
                File.Copy(masterDnaPath, addInDnaPath, false);
                var dnaContent = File.ReadAllText(addInDnaPath);
                dnaContent = dnaContent.Replace("%AddIn_Path%", externalLibraryPath);
                File.WriteAllText(addInDnaPath, dnaContent);
            }

            ExcelIntegration.RegisterXLL(addInXllPath);
        }
示例#2
0
 public static void RegisterSlave()
 {
     Console.Beep();
     Console.Beep();
     Console.Beep();
     Console.Beep();
     Excel(xlcMessage, true, $"Loading {path}");
     Thread.Sleep(1000);
     ExcelIntegration.RegisterXLL(path);
 }
示例#3
0
 void LoadXLL(string path)
 {
     try {
         logger.Debug($"RegisterXLL '{path}'");
         Directory.SetCurrentDirectory(Path.GetDirectoryName(path));
         var ans = ExcelIntegration.RegisterXLL(path);
     }
     catch (Exception ex) {
         logger.Error(ex, $"Cannot load XLL");
     }
 }
        // Called on the VsLinkServer thread - should not block
        public static void VsLinkMessageHandler(VsLinkMessage message)
        {
            var registerXllMessage = message as RegisterAddInMessage;

            if (registerXllMessage != null)
            {
                if (registerXllMessage.AddInPath.EndsWith(".xll"))
                {
                    ExcelAsyncUtil.QueueAsMacro(() => ExcelIntegration.RegisterXLL(registerXllMessage.AddInPath));
                }
                else if (registerXllMessage.AddInPath.EndsWith(".dll"))
                {
                    ExcelAsyncUtil.QueueAsMacro(() => AddInLoader.RegisterDll(registerXllMessage.AddInPath));
                }
            }
        }
示例#5
0
 // Running in macro context.
 static void ReloadAddIn(string xllPath)
 {
     ExcelIntegration.RegisterXLL(xllPath);
 }
示例#6
0
        /// <summary>
        /// Kinda sucks that the moment because I need to copy the Excel.Dna.Diagnostics.Child1 dll to the Excel.Dna.Diagnotstics bin folder.
        /// because im loading the XLL and not the XLL packed. the DLLs need to get wrapped up together.
        /// otherwise the copying process is annoying. or i create a post build script to do it.
        /// Summary:
        //     Loads an XLL code resource and automatically registers the functions and
        //     commands contained in the resource.
        //   Application.RegisterXLL();
        /// </summary>
        public static void RegisterChildren()
        {
            var childPath = @"C:\Users\Chris W\Documents\GitHub\ExcelDnaTest\Excel.Dna.Diagnostics.Child1\bin\Debug\Excel.Dna.Diagnostics.Child1-AddIn-packed.xll";

            ExcelIntegration.RegisterXLL(childPath);
        }
 public override object RegisterXLL(string xllPath)
 {
     return(ExcelIntegration.RegisterXLL(xllPath));
 }