简体   繁体   English

如何从excel中的公式调用VSTO函数?

[英]How do I call a VSTO function from a formula in excel?

I'd like to be able to call a function exposed by a VSTO addin from a cell in an excel worksheet. 我希望能够从excel工作表中的单元格调用由VSTO插件公开的函数。 More specifically, if I have a VSTO function Foo() that returns "bar" I'd like to be able to write =Foo() in A1 which evaluates to "bar" on calculation. 更具体地说,如果我有一个返回“bar”的VSTO函数Foo(),我希望能够在A1中写入= Foo(),计算结果为“bar”。

Is this possible? 这可能吗? What are the key steps I'd need to take? 我需要采取哪些关键步骤?

The prospect of being able to leverage managed code and the VS08 IDE for excel development is very appealing. 能够利用托管代码和VS08 IDE进行Excel开发的前景非常吸引人。 I thought VSTO would allow me to easily do this but I'm no longer sure. 我以为VSTO会让我轻松做到这一点,但我不再确定。 Am I misunderstanding the architecture here? 我在这里误解了这个架构吗? The documentation is a little shoddy. 文档有点粗制滥造。

Excel-DNA (which I develop) is an open-source project that allows you to create user-defined worksheet functions (UDFs) for Excel, as you describe. Excel-DNA (我开发)是一个开源项目,允许您为Excel创建用户定义的工作表函数(UDF),如您所述。

With Excel-DNA you can also make full-featured Excel add-ins that include ribbon customization, macros, async function and RTD servers. 使用Excel-DNA,您还可以制作功能齐全的Excel加载项,包括功能区自定义,宏,异步功能和RTD服务器。 Excel-DNA uses the native Excel XLL interface to integrate with Excel, so you get very good performance too, compared to solutions based on COM integration. Excel-DNA使用原生Excel XLL界面与Excel集成,因此与基于COM集成的解决方案相比,您也可以获得非常好的性能。

I don't believe you can do so directly, though you can use a VBA wrapper, see for example 我不相信你可以直接这样做,虽然你可以使用VBA包装器,例如参见 http://blogs.msdn.com/pstubbs/archive/2004/12/31/344964.aspx . http://blogs.msdn.com/pstubbs/archive/2004/12/31/344964.aspx

You can also use a third party product like ManagedXll to create Excel UDFs in managed code. 您还可以使用ManagedXll等第三方产品在托管代码中创建Excel UDF。

I think you can make use of COM Interop.. here is a webpage where I've seen the process described. 我想你可以使用COM Interop ..这是一个网页,我已经看到了描述的过程。

http://www.cpearson.com/excel/creatingnetfunctionlib.aspx http://www.cpearson.com/excel/creatingnetfunctionlib.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM