C# - Excel Add-in (XLL) - Best Practises?

D

David F

I've been asked to develop an Excel Add-in to provide specific Math functions
and I have a few questions about implementing the Add-in in C#.

Question 1:
Are there any best practise examples in C# of Excel XLL's?


Question 2:
If I'm only supplying maths functions I've found the following to be pretty
effective;
using System;
using System.Runtime.InteropServices;

namespace NAddIn
{
[ClassInterface(ClassInterfaceType.AutoDual)]
public class Functions
{
public Functions()
{
}

public double Add2(double v1, double v2)
{
return v1 + v2;
}

[ComRegisterFunctionAttribute]
public static void RegisterFunction(Type t)
{
Microsoft.Win32.Registry.ClassesRoot.CreateSubKey("CLSID\\{" +
t.GUID.ToString().ToUpper() + "}\\Programmable");

Microsoft.Win32.RegistryKey key =
Microsoft.Win32.Registry.ClassesRoot.CreateSubKey("CLSID\\{" +
t.GUID.ToString().ToUpper() + "}\\InprocServer32");
key.SetValue("", @"C:\Windows\System32\mscoree.dll");
}

[ComUnregisterFunctionAttribute]
public static void UnregisterFunction(Type t)
{
Microsoft.Win32.Registry.ClassesRoot.DeleteSubKey("CLSID\\{" +
t.GUID.ToString().ToUpper() + "}\\Programmable");
}
}
}

Is building a standard dll with the above method attributes ok or should I
use a full blown c# office addin project as a basis to work from. Note I
won't need to interact with the Excel GUI (add toolbar buttons etc.).


Question 3:
How can I support a function description in the Excel->Insert Function ->
Select a Function dialogue?


Question 4:
How can I support context sensitive help for my C# library methods?
Excel->Insert Function -> Select a Function, currently displays 'No Help
Available'.


Question 5:
Is it possible to have intellisense within the worksheet area? Such as you
get when you enter =Exp(.


I've spent the last few days looking generally at C# Excel Add-ins and there
have been no examples of function descriptions, help or context sensitive
help with a library build in C#. Only C++ examples come close, in a worst
case scenario I was hoping for 'Managed' C++.


Hopefully this is the newsgroup to get a few answers.

Many Thanks

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top