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/