Excel 加载项在类库之间共享内存

发布于 2025-01-01 15:07:46 字数 1615 浏览 6 评论 0原文

环境:C#、.NET 3.5、Windows 7 64、Excel 2007、Visual Studio 2010

我有一个 VS2010,有 3 个项目:

类库

List<BusinessClass> 

Projet « Business »: 具有全局静态变量Project 的 « Add-In » : 可扩展性共享 Add-in 和 Add-In 类:

[GuidAttribute("A9E83593-395F-4112-855D-A68C5088151F"), ProgId("eFrontCubeAddIn.CubeAddIn")]
public class CubeAddIn : Object, Extensibility.IDTExtensibility2, ICustomTaskPaneConsumer {…}

Excel 将调用 OnConnection,我将使用 Excel 对象(ExcelApp = (Excel.Application)application;) 进行交互。 “Add-In”内的所有交互都是通过 COM (InvokeMember) 完成的。 List 是从“加载项”

项目 « Formulas »: 类库中创建和填充的。一种 UDF Excel 特定公式。方法是使用以下模型构建的,并使用 [ComRegisterFunctionAttribute]RegisterFunction(Type type) 注册...

[Guid("5268ABE2-9B09-439d-BE97-2EA60E103EF6")]
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
public class MyFunctions {
public double MyUdfFunction(double number1, double number2) {
{
return number1 * number2;
}

我的问题很容易解释:我在项目“Add In”中有一个功能区和一个自定义窗格,填充 List;. 当 Excel 用户在单元格中输入“=MyUdfFunction(6 ;7)”时,将调用“公式”中的我的方法。 由于它来自不同的进程(来自 Excel),UDF 无法访问“Business”实例,并且 List 无法访问。

UDF 有时可能被调用超过 500.000 次 出于速度原因,我不想插入在循环中调用 UDF 的 VBA 脚本。 出于速度原因,我不想使用共享内存、命名管道、WCF 或其他工件。 不想使用 UDF 服务(无法使用 Sharepoint 服务器)。

我知道当您处于不同的进程中时,您无法使用其他进程中的数据。

有办法让“公式”直接访问“业务”实例吗?就像在同一个流程中拥有所有 3 个项目一样...

提前致谢 让·玛丽

Environment : C#, .NET 3.5 , Windows 7 64, Excel 2007, Visual Studio 2010

I have a VS2010 with 3 projects :

Projet « Business » : A class library with a global static variable

List<BusinessClass> 

Project « Add-In » : Extensibility Shared Add-in and the Add-In class:

[GuidAttribute("A9E83593-395F-4112-855D-A68C5088151F"), ProgId("eFrontCubeAddIn.CubeAddIn")]
public class CubeAddIn : Object, Extensibility.IDTExtensibility2, ICustomTaskPaneConsumer {…}

Excel will call OnConnection and I will use the Excel object(ExcelApp = (Excel.Application)application;) to interact. All the interactions within "Add-In" are done via COM (InvokeMember).
The List<BusinessClass> is created and filled from "Add-In"

Project « Formulas » : Class Library. One UDF Excel specific formula. Methods are built using the following model and registered using [ComRegisterFunctionAttribute]RegisterFunction(Type type)…

[Guid("5268ABE2-9B09-439d-BE97-2EA60E103EF6")]
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
public class MyFunctions {
public double MyUdfFunction(double number1, double number2) {
{
return number1 * number2;
}

My problem is very simple to explain: I have a Ribbon and a Custom Pane in the project « Add In » filling the List<BusinessClass>.
When the Excel User enters ‘=MyUdfFunction(6 ;7)’ in a cell, my method in « Formulas » is called.
As it comes from a different process (from Excel) the UDF has no access to « Business » instances and List<BusinessClass> is unreachable.

The UDF could be sometimes called more than 500.000 times
For speed reasons, I dont want to insert a VBA script calling my UDF in the loop.
For speed reasons, I dont want to use Shared memory, Named pipes, WCF or other artifacts.
Dont want to use the UDF services (cant use Sharepoint server).

I know that when u are in a different process you cant use data from other processes.

Any idea to give "Formulas" direct access to "Business" instance ? Like having ALL 3 projects in the same process...

Thanks in advance
Jean Marie

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小巷里的女流氓 2025-01-08 15:07:46

您的“公式”项目是一个 Excel 自动化插件。 Add-in Express 允许您在同一程序集中拥有 COM 插件和 XLL 插件;它们将加载到同一个 AppDomain 中,请检查 操作方法:在一个程序集中创建 COM 加载项、XLL UDF 和 RTD 服务器。更准确地说,自动化插件也可以在同一个程序集中实现,但在所有情况下,您不能将自动化插件加载到同一 AppDomain 中。

另请注意另一篇博客: 从 Excel XLL 加载项调用 COM 加载项:高级示例

Your "Formulas" project is an Excel Automation add-in. Add-in Express allows you to have a COM add-in and XLL add-in in the same assembly; they will load into the same AppDomain, check HowTo: Create a COM add-in, XLL UDF and RTD server in one assembly. More precisely, an Automation add-in can be implemented in the same assembly, too but you cannot have the Automation add-in loaded in the same AppDomain in all situations.

Also note another blog: Invoking a COM add-in from an Excel XLL add-in: advanced sample.

野味少女 2025-01-08 15:07:46

为了提高速度,您需要尽可能使用 XLL 接口,特别是对于 UDF。我建议您考虑使用 Addin Express(收费)或 Excel DNA(免费),这两种方法都可以在进程内使用 Interop-COM 和 XLL 为您提供与 Excel 的 .NET 接口。

For speed you need to be using the XLL interface where possible, particularly for UDFs. I suggest you look at using Addin Express (costs) or Excel DNA (free), both of which give you .NET interfaces to Excel using both Interop-COM and XLL in-process.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文