.NET 6中使用Microsoft.Office.Interop.Word无法打开Office文件求助
.NET 6中使用Office Interop打开Word文件的问题
在基于.NET 6的C#应用中尝试打开Office文件时出现异常,但该功能在.NET Framework环境下可正常运行。官方NuGet包Microsoft.Office.Interop.Word似乎仅支持到Office 2016版本,即使添加了Microsoft Word 16.0 Object Library的COM引用,问题依然存在。
代码示例如下:
using Microsoft.Office.Interop.Word; private void button2_Click(object sender, EventArgs e) { var ap = new Microsoft.Office.Interop.Word.Application(); Document document = ap.Documents.Open(@"C:\Users\name\Desktop\test.docx"); ap.Visible = true; }
点击按钮时抛出异常:
System.IO.FileNotFoundException: 'Could not load file or assembly 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'. The system cannot find the file specified.'
当前Office 365版本是否真的不被该组件支持?已确认C:\Windows\assembly\GAC_MSIL目录中存在Microsoft.Office.Interop.Word程序集。
内容的提问来源于stack exchange,提问作者mountainred
相关产品推荐
相关产品推荐

