【发布时间】:2019-02-07 20:22:20
【问题描述】:
使用 PIA (https://docs.microsoft.com/en-us/visualstudio/vsto/office-primary-interop-assemblies?view=vs-2017),我可以轻松打开 word 文件并在其中执行任务。但是 PIA 不再适用于 Office 2016。我的问题是,是否有替代方案?现在有“Visual Studio 的 Office 开发人员工具”。我可以用吗?
如何与 PIA 配合使用:
Application app = null;
Document doc = null;
app = new Microsoft.Office.Interop.Word.Application();
doc = Microsoft.Office.Interop.Word.Documents.Open(filePath);
// .. do something
doc.Close();
app.Quit();
是否可以使用“Visual Studio 的 Office 开发人员工具”中的 Microsft.Office.Tools.Word 做类似的事情?
【问题讨论】:
-
你为什么这么说
the interop Mode is not available anymore for Office 2016.?互操作不是模式。"Office Developer Tools for Visual Studio"没有代替 interop 使用,它们以其他名称使用超过 10 年来创建 Office 插件和扩展 -
你是对的。我实际上是指 Office 主要互操作程序集。我改变了我的问题,希望现在很清楚。但据我所知,Office 2016 的 pia 不再可用,请参阅我提供的链接。
-
PIA 很方便,因此您不必添加对 COM 对象库本身的引用。该链接也没有说它们也已停产。在任何情况下,PIA 都针对特定的 COM 接口版本。那些并没有消失。只要安装的 Word 版本支持旧的 PIA,它们仍然可以工作。同样,并不意味着 Word 2016 没有 PIA