【问题标题】:Can't find the Microsoft.Office.Interop.Excel Package for Excel 2016找不到适用于 Excel 2016 的 Microsoft.Office.Interop.Excel 包
【发布时间】:2020-11-06 17:11:03
【问题描述】:

我正在尝试使用 Visual Studio 2019 中的 C# 程序在 Excel 2016 中运行宏。这是该程序开头的样子(只是尝试打开工作簿):

using System;
using Microsoft.Office.Interop.Excel;

namespace CurrentStudyRun
{
    class Program
    {
        static void Main(string[] args)
        {
            object oMissing = System.Reflection.Missing.Value;

            ApplicationClass objExcel = new ApplicationClass();
            objExcel.Visible = true;
            Workbooks workbooks = objExcel.Workbooks;
            Workbook oBook = null;

            oBook = workbooks.Open("path");


        }
    }
}

为了做到这一点,我从 Visual Studio 安装程序安装了他的 VSTO 工作负载 (Workload Picture) 并添加了 Microsoft Office 16.0 Object Library。但是,当我添加 Nuget 包时,我只看到 Excel 2013 as shown 的包。使用top包时得到的是here显示的错误。

【问题讨论】:

    标签: c# excel package nuget


    【解决方案1】:

    我使用过 Excel 2016,测试成功。

    清单

    1. 检查导入的 dll 是否在文件夹中
      1.1) 如果您没有找到它们,请手动将它们放入 bin 文件夹中
    2. Microsoft Excel 应安装在您的计算机中,
      2.1) 并且 Microsoft 产品具有有效的许可证
    3. 如果之前的尝试失败,请尝试在 GAC 中注册 DLL

    【讨论】:

      【解决方案2】:

      已解决 该清单很有帮助,因此如果您遇到此问题,请务必执行这些操作,但最终为我解决的问题是将您使用的引用的嵌入互操作类型更改为 True。这样做:

      1. 右键单击依赖项(本例中为 Microsoft.Office.Interop.Excel)并选择属性
      2. 将嵌入互操作类型更改为“是”(我的没有选择任何内容)

      感谢彼得和艾莉亚的回答。

      【讨论】:

        猜你喜欢
        • 2021-10-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多