[英]How to use ExcelDNA developed XLL from C# without Excel
we have built XLL in C# using ExcelDna as described in https://excel-dna.net/ --- everything works when tested from Excel. 我们已经按照https://excel-dna.net/中所述使用ExcelDna在C#中构建了XLL,---从Excel中进行测试后,一切正常。
We would like to be able to use this XLL in other .NET projects -- in other words, how do we "host" this XLL from .NET? 我们希望能够在其他.NET项目中使用此XLL-换句话说,我们如何从.NET“托管”该XLL? The XLL does not appear to be a valid .NET assembly -- so I cannot add it as a .NET reference to other projects
XLL似乎不是有效的.NET程序集-因此我无法将其作为.NET引用添加到其他项目
Is it done through ExcelDna.Integration dll somehow (which IS a .net assembly)? 它是通过ExcelDna.Integration dll以某种方式完成的(它是.net程序集)吗?
Thank you 谢谢
Excel-DNA is just a glue between Excel and .NET assemblies. Excel-DNA只是Excel和.NET程序集之间的粘合剂。
If you want to reuse functionality that is inside a .NET assembly that is being loaded by an Excel-DNA Add-In (ie XLL
), then you don't need the XLL
for anything... All you need is the .NET assembly that the XLL
is loading - Add a reference to that in your .NET application and you're good to go... Just like you would do with any other class library. 如果要重用Excel-DNA加载项(即
XLL
)正在加载的.NET程序集内的功能,则不需要XLL
做任何事情...所有您需要的是.NET装配该XLL
是负载-在你的.NET应用程序添加到一个参考,你是好去...就像你会与任何其他类库做。
In other words, inside your .dna
file that is used by Excel-DNA to determine what to load, you have something that looks like this: 换句话说,在Excel-DNA用于确定加载内容的
.dna
文件中,您将看到以下内容:
<DnaLibrary Name="Your Add-In" RuntimeVersion="v4.0">
<ExternalLibrary Path="YourAssembly.dll" ExplicitExports="false" ... />
</DnaLibrary>
YourAssembly.dll
is already the .NET assembly that contains the functions that are exposed to Excel-DNA. YourAssembly.dll
已经是.NET程序集,其中包含公开给Excel-DNA的功能。
More importantly, if you know you're going to have different .NET "clients" for your functions, then you should design for that, isolate the reusable functions in a dedicated assembly, and have your Excel-DNA assembly reference that, and expose the functions to Excel, instead of forcing clients to depend on Excel-DNA assemblies. 更重要的是,如果您知道要为功能使用不同的.NET“客户端”,则应为此进行设计,将可重用功能隔离在专用程序集中,并使用您的Excel-DNA程序集引用并公开将功能传递给Excel,而不是强制客户端依赖Excel-DNA程序集。
eg 例如
Functions.dll
(does not reference anything) Functions.dll
(不引用任何内容) ExcelAddIn.dll
(references Functions.dll
) ExcelAddIn.dll
(引用Functions.dll
) MyCsApp.exe
(references Functions.dll
) MyCsApp.exe
(引用Functions.dll
) FunctionsComInterop.dll
(references Functions.dll
) FunctionsComInterop.dll
(引用Functions.dll
) MyCppApp.exe
(calls FunctionsComInterop.dll
) MyCppApp.exe
(调用FunctionsComInterop.dll
) In the example above: 在上面的示例中:
Functions.dll
does not reference any Excel-DNA assembly and it does not expose anything via to COM. Functions.dll
不引用任何Excel的DNA组件,它不通过对COM暴露任何东西。 It should have as little dependencies as possible (ideally none!) 它应该具有尽可能少的依赖性(理想情况下没有依赖性!)
ExcelAddIn.dll
makes the bridge to Excel-DNA and exposes Excel functions that can be called by Excel through Excel-DNA. ExcelAddIn.dll
成为与Excel-DNA的桥梁,并公开了Excel可以通过Excel-DNA调用的Excel函数。 These functions simply forward calls to the Functions.dll
assembly... Nothing more. 这些函数只是将调用转发到
Functions.dll
程序集……仅此而已。
FunctionsComInterop.dll
makes the bridge to C++ and exposes COM functions that can be called by the C++ app. FunctionsComInterop.dll
搭建了通往C ++的桥梁,并公开了可由C ++应用程序调用的COM函数。 These functions simply forward calls to the Functions.dll
assembly... Nothing more. 这些函数只是将调用转发到
Functions.dll
程序集……仅此而已。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.