如何使用 vb.net 以编程方式操作 MS Word 文档 (.docx)?

How do you manipulate a MS Word document (.docx) programmatically using vb.net?

我正在尝试使用 vb.net 从 .docx 文件 (MS Word 2013) 中读取并在同一文档中查找和替换多个单词。我不想在 vb.net 中使用插件或附加组件,而是自己编写程序。

vb.net 中的哪些库或引用将使我能够使用 .docx 文件扩展名处理 MS Word 文档。

Visual Studio 2013 的任何相关 vb.net 代码将不胜感激。

我找到了以下相关信息 (https://support.microsoft.com/en-us/kb/316383),尽管我发现很难将其适应 Visual Studio 2013。

下面是直接来自 Visual Studio 2013 的 COM 引用列表,唯一与上述 link 相似的选项似乎是下面屏幕打印中的选中项:

似乎在 "connecting the dots" 每个人的评论(谢谢)之后,我缺少一个与 MS Word 2013 关联的 "Microsoft Word 14.0 Object Library" 一起使用的导入参考。

参考https://support.microsoft.com/en-us/kb/316383, the imports reference that I found was adapted from the question: How to load Word Object Library properly in Visual Studio Express即在对象class的顶部添加以下内容解决了这个问题:

Imports Microsoft.Office.Interop

您可以使用 DocX to replace text in one or muliple documents, check the sample code here - Replace text across many documents in Parallel 。希望我没有误会你。

要运行您的应用程序,您需要在 PC 上安装 MS Word。我会考虑改用 Open XML SDK。有关详细信息,请参阅 Welcome to the Open XML SDK 2.5 for Office