所以,我正在使用使用肋骨杆和一些外部DLL的Excel Addin(常规VSTO项目(。因为需要在Excel中导入某些用户定义的功能(UDF(,所以我读到您只能通过使用COM对其进行注册,所以我使用功能等的接口进行了此操作。我进行了注册,如https://theofficecontext.com/2013/06/08/update-creating-cetcel-excel-excel-udfs-in-c/注册工作正常,我的导入功能可以在Excel中调用。我使用一些对话框让用户设置一些用于UDF的变量,我发现这两件事是在单独的addin对象中管理的。
这就是问题所在。因为它们是两个不同的对象,所以我输入对话框的所有内容都无法由UDF访问。
onconnection((是从excel内部调用的,当UDF通过与工作轴交互加载时。
namespace myExcelAddin
{
public partial class ThisAddIn
{
public static int iUser = 0;
// .. some other static variables
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
// some startup work
}
}
}
namespace myExcelAddin
{
[ComVisible(true)]
public interface IFunctions
{
// ... some functions
}
[ComVisible(true)]
[GuidAttribute("1D3001F4-5307-49A6-98F2-B3B76B3D0AA3"),
ProgId("myExcelAddin.Functions"),
ClassInterface(ClassInterfaceType.None),
ComDefaultInterface(typeof(IFunctions))]
public partial class Connect : Object, Extensibility.IDTExtensibility2, IFunctions
{
// ... implementation of interface functions
}
public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
{
// get a reference to the instance of the add-in
Application = application as Excel.Application;
thisAddIn = addInInst;
}
[ComRegisterFunctionAttribute]
public static void RegisterFunction(Type type)
{
//... registration work
}
[ComUnregisterFunctionAttribute]
public static void UnregisterFunction(Type type)
{
// ... unregistration work
}
}
那么,是否有可能获取用户输入的内容?因为两者的全球都处理也有所不同...
这似乎是复杂的问题,但我的想法很少:
1(注册表-HKEY_CURRENT_USER如果数据量相当小
2(将其放入文件中,并从其他Addin
中读取文件3(这看起来最真实 - 使用Excel运输数据 - 即创建隐藏的工作表并将数据放入其中 - 但是如果您不想修改现有工作簿