首页 > 解决方案 > 有没有办法在 c# 中使用带有版本独立的 interop excel 生成 excel 报告?

问题描述

我正在使用 Visual Studio 2019 并使用 Nuget 安装“Microsoft.Office.Interop.Excel V 15.0.4795.1000”。当我生成 excel 报告时,它可以与“Microsoft Office 2013”​​一起正常工作。但是,收到“Microsoft Office Home and Business 2019”的错误消息。

错误消息:HRESULT 异常:0x800A03EC 异常:System.Runtime.InteropServices.COMException (0x800A03EC):HRESULT 异常:0x800A03EC

我假设 Office 2019 不支持 Interop Excel V 15。

我使用下面的代码来创建 excel 应用程序。

using ExApp = Microsoft.Office.Interop.Excel;
ExApp.Application xlApp = new ExApp.Application();

后来,我还尝试使用下面的代码,认为它可以与多个版本的 excel 一起使用。

Type ExcelType = Type.GetTypeFromProgID("Excel.Application");
dynamic xlApp = Activator.CreateInstance(ExcelType);

有没有办法可以在任何版本的 excel(2007 到 2019)上用 c# 生成 excel 报告?

至少,我需要“Microsoft Office Home and Business 2019”的解决方案。

标签: office-interopcom-interopexcel-interop

解决方案


推荐阅读