c# - Excel VSTO 如何工作?

标签 c# excel vsto clr-hosting

Excel VSTO 如何工作?如果我在 Visual Studio 2005 中创建一个 Excel 工作簿解决方案,我就可以愉快地编写代码,完全访问 Excel 对象模型,甚至可以将 Excel 工作表视为设计界面。当我构建解决方案时,我得到一个 .XLS 文件和一个 .DLL(包含我的 C# 代码)。

我现在只需双击 .XLS 即可启动 Excel 工作表,我的工作表可以使用我的所有 C# 代码和我放在工作表上的任何控件等运行。

工作表如何引用 .DLL? Excel 工作簿/工作表的哪一部分告诉它需要启动 CLR 并托管我的程序集?

最佳答案

根据 this (感谢 PintSizedCat)对于 Excel 2003 会发生以下情况:

The Microsoft Office application checks the custom document properties to see whether there are managed code extensions associated with the document. For more information, see Custom Document Properties Overview.

If there are managed code extensions, the application loads AddinLoader.dll. This is an unmanaged DLL that is the loader component for the Visual Studio 2005 Tools for Office Second Edition runtime. For more information, see Visual Studio Tools for Office Runtime Overview.

AddinLoader.dll loads the .NET Framework and starts the managed portion of the Visual Studio Tools for Office runtime.

The Visual Studio Tools for Office runtime creates an application domain, sets policy for the application domain not to trust the My Computer Zone, and checks the code access security policy store to find a policy for the customization assembly.

The .NET Framework validates the evidence presented by the assembly against the policy. If it fails, an error is raised. If it passes, the process continues.

If the customization uses a deployment manifest, the Visual Studio Tools for Office runtime uses it to check for assembly updates. If any updates are necessary, they are performed now.

The Visual Studio Tools for Office runtime loads the assembly into the application domain.

The Visual Studio Tools for Office runtime calls the Startup event handler in your customization assembly. For more information, see Visual Studio Tools for Office Project Events.

在我的测试项目的 Excel 工作簿中,我有两个自定义属性:

_程序集名称,值 = * _AssemblyLocation,值 = {533b2c13-a125-418a-bfff-9546b0762807}

我想这些是将 VSTO 运行时定向到我的程序集的属性。

关于c# - Excel VSTO 如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/536130/

相关文章:

c# - 在第三方库代码中中止执行的最安全方法

excel - 为什么第一个随机数总是一样的?

excel - 根据 A 列的每个不同值获取 B 列的最大值

excel - 如果条件字符串长于 256 个字符,COUNTIF/SUMIF 会给出错误

c# - VSTO Outlook 插件 : Cannot use Explorer Close event

c# - 在没有编码的 URI 模板中使用正斜杠 ('/' )

c# - 在运行时动态更改 Win8 XAML 应用程序中的 ThemeResource/StaticResource 或其他?

excel - 确定 Popup 是否位于 Excel 前台

C# 加载项 Excel : ActiveSheet

c# - 通过 http post 接收的值对于 AngularJS 和 Web api 2 为空