【问题标题】:Make assembly COM-Visible breaks build for Excel VSTO addin为 Excel VSTO 插件构建程序集 COM-Visible 中断
【发布时间】:2020-01-22 10:03:44
【问题描述】:

我正在开发一个 C# VSTO Excel 插件,它将从一些 excel VBA 中调用。因此我必须:

  • 注册 COM 互操作,然后
  • 使程序集 COM 可见

寄存器不会破坏任何东西,但使程序集 COM 可见会产生以下两个错误:

Error       The assembly "C:\Users\...\ExcelInterop.dll" could not be converted to a type library. Type library exporter encountered an error while processing 'ExcelInterop.ThisAddIn, ExcelInterop'. Error: Error loading type library/DLL.   ExcelInterop            
Error       The assembly 'Microsoft.Office.Tools.Common.v4.0.Utilities, Version=10.0.0.0, Culture=neutral, PublicKeyToken=...' is not registered for COM Interop. Please register it with regasm.exe /tlb.  ExcelInterop            

如果我创建一个普通的类库项目,它工作正常,所以我猜它与ThisAddin.cs 有关,它将 C# 链接到 excel 工作表。请注意,我没有从生成的样板文件中更改 ThisAddin.cs

我想做什么?

我必须从我的 VSTO Excel 插件导入/导出一些 Excel 数据并将其发送到业务 API(无法从 VBA Excel 插件访问)。但是,VBA 为客户端提供 UI(除其他外),这就是为什么我不能只用 C# 重写整个 VBA 插件。

【问题讨论】:

    标签: c# excel vsto add-in


    【解决方案1】:

    阅读以下 SO 帖子帮助我更好地理解 COM-Visible 的含义...

    https://stackoverflow.com/questions/3699767/register-for-com-interop-vs-make-assembly-com-visible

    我只需要标记我需要在 VBA 中使用的类,如下所示,而不是使整个程序集 COM-Visible:

    [GuidAttribute("54c23560-db8d-4ec9-a19f-f920ba0558c0"), ComVisible(true)]
    public class Manager
    {
    ...
    }
    

    我从 https://www.guidgenerator.com/online-guid-generator.aspx 生成了 Guid。

    【讨论】:

    • 非常感谢。我打破了脑袋想知道我在哪里可以得到 GUID,你救了我。上帝保佑你!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-16
    • 2012-05-30
    • 2017-06-07
    • 2020-05-12
    • 1970-01-01
    • 2020-09-13
    • 1970-01-01
    相关资源
    最近更新 更多