2013-03-11 56 views
0

我有一个旧的Excel插件(用VBA编写),现在我使用.NET,ExcelDNA和NetOffice重新编写旧插件。在旧插件中,在新插件中有一个UDF,例如OldUDF,有一个NewUDF,两个UDF执行相同的操作并接受相同的参数。但它们有不同的函数名称。 由于遗留原因,一些客户端有旧插件,有些客户端有新的插件。 有些客户都有。 当他们同时安装了Excel插件时,我想提供一个复选框,指出在新插件中将forwardUDF转发到newUDF。当复选框被选中时,oldUDF作为newUDF被转发。如果未选中复选框,oldUDF将不会被转发。 我在new addin中定义了旧的UDF & newUDF,但不知道如何在取消选中复选框时删除oldUDF的definiatino。由于如何以编程方式删除Excel UDF

编辑:

这里是我试过,但它不工作。

#if FORWARD 
     public static object OldUDF([ExcelArgument(AllowReference = true, Name = "Symbol", 
      Description = "is a futures symbol as defined in *** Database.")]string symbol, 
      [ExcelArgument(AllowReference = true, Name = "Column", 
       Description = "is a column associated with a symbol")]string column, 
      [ExcelArgument(AllowReference = true, Name="Date", 
       Description = "is the date for which you want the value")]object onDate, 
       object fillOpt, object frequency) 
     { 
      return NewUDF(symbol, column, onDate, fillOpt, frequency); 
     } 
#endif 

在的AutoOpen(), 我会读前值从文件(true或false),如果前锋是真实的,

 var forward = Helper.ReadForwardOldUDFSettingFromAFile(); 
     if(forward) 
     { 
      #define FORWARD 
     } 

但我得到一个编译错误

再次编辑: 我设法注册成功 我把OldUDF的声明放在一个单独的dll中,比如oldUDF.dll 创建另一个oldUDF.xll,oldUDF.dna。

在AutoOpen中,我将检查转发值(来自文件)是否为真,我会做 Excel.Application.RegisterXLL(“olderUDF.xll”); 这工作正常。

但是,如果正向值为false,我找不到在C#中注销或删除XLL的方法?

编辑:我发现http://msdn.microsoft.com/en-us/library/office/bb687866.aspx,但不知道如何使用它在C#

感谢

+0

你不介意与我们分享至少一个相关的一块你的努力 - [?你尝试过什么]刚刚在支持(http://whathaveyoutried.com/) – 2013-03-11 17:59:55

+0

@PeterL,谢谢,请参阅编辑 – toosensitive 2013-03-11 18:35:48

+0

我发现http://msdn.microsoft.com/en-us/library/office/bb687866(v=office.14).aspx,但它没有示例显示如何使用它 – toosensitive 2013-03-12 20:54:53

回答

0

谢谢,霍弗特。他回答了另一组的问题。有用! http://exceldna.codeplex.com/discussions/436393

private static void UnregisterFunction(string name) 
{ 
    // get the path to the XLL 
    var xllName = XlCall.Excel(XlCall.xlGetName); 

    // get the registered ID for this function and unregister 
    var regId = XlCall.Excel(XlCall.xlfEvaluate, name); 
    XlCall.Excel(XlCall.xlfSetName, name); 
    XlCall.Excel(XlCall.xlfUnregister, regId); 

    // reregister the function as hidden and then unregister (clears the function wizard) 
    var reregId = XlCall.Excel(XlCall.xlfRegister, xllName, "xlAutoRemove", 
    "I", name, ExcelMissing.Value, 2); 
    XlCall.Excel(XlCall.xlfSetName, name); 
    XlCall.Excel(XlCall.xlfUnregister, reregId); 
} 
相关问题