using System;
using Microsoft.Office.Excel.Server.Udf;
namespace myUdfs
{
[UdfClass]
public class Class1
[UdfMethod]
public string Greetings()
return "Hello World";
}
public string Greetings(string name)
string result = "Hello World";
if (String.IsNullOrEmpty(name))
return result;
return String.Format("Hello {0}", name);
public string Greetings2(params string[] args)
string result = "Hello ";
if (args.Length == 0)
foreach (string item in args)
if (!string.IsNullOrEmpty(item))
result += " " + item;
public string DateTimeNow()
return DateTime.Now.ToString();
[UdfMethod(IsVolatile = true)]
public string DateTimeNowReal()
[UdfMethod(ReturnsPersonalInformation = true)]
public string GetUltraSecretData()
string userName = Thread.CurrentPrincipal.Identity.Name;
if (userName.ToLower().Contains("admin"))
return "Votre Mot de Passe : $tr0ng P4$$w0rÐ (Strong Password)";
else
return "Vous n'êtes pas autorisé à voir cette donnée.";
public string GetTypeOfParameter(object[] param)
return param[0].GetType().ToString();
using System.Runtime.InteropServices;
using Microsoft.Win32;
[ProgId("myUdfs.Class1")]
[ClassInterface(ClassInterfaceType.AutoDual)]
[Guid(Class1.Guid)]
[ComVisible(true)]
public const string Guid = "8ED508EB-0473-44be-974B-DFC607F8F230";
[ComRegisterFunction]
public static void RegistrationMethod(Type type)
if (typeof(Class1) != type)
return;
RegistryKey key = Registry.ClassesRoot.CreateSubKey("CLSID\\{" + Guid + "}\\Programmable");
key.Close();
[ComUnregisterFunction]
public static void UnregisterationMethod(Type type)
Registry.ClassesRoot.DeleteSubKey("CLSID\\{" + Guid + "}\\Programmable");