简体   繁体   English

使用Microsoft.Office.Interop.Word 2016/365编码和2010生产的Visual Studio 2017 C#项目

[英]Visual Studio 2017 C# project with Microsoft.Office.Interop.Word 2016/365 coded and 2010 production

I'm coding one of my first projects in Visual Studio 2017 using the Microsoft Office Interop Tools to basically open some Word files, extract some content and export it to an XML file. 我正在使用Microsoft Office Interop Tools编写Visual Studio 2017中的第一个项目之一,以基本上打开一些Word文件,提取一些内容并将其导出为XML文件。 I know that on the target machine Office should be installed and actually on that PC a 2010 installation is licensed, while on my PC I have a 365 suite. 我知道应该在目标计算机上安装Office,并且实际上在该PC上已许可2010安装,而在我的PC上我有365套件。

The first build was working only on my PC, with missing references errors to the interop library on the production PC, so I've downloaded the Microsoft Office 2010: Primary Interop Assemblies Redistributable https://www.microsoft.com/en-us/download/details.aspx?id=3508 to include as a reference in my project, replacing the 2016 one. 第一次构建仅在我的PC上运行,缺少对生产PC上的互操作库的引用错误,因此我下载了Microsoft Office 2010:可重新分发的主要互操作程序集https://www.microsoft.com/zh-cn /download/details.aspx?id=3508作为我的项目的参考,以取代2016年的项目。

First difficulty was: Once installed I cannot find the files on my drive, nor a reference inside visual studio, nor in the documentation. 第一个困难是:安装后,我找不到驱动器上的文件,也找不到Visual Studio中的参考文件,也找不到文档中的文件。 Is there any info about where to pick the dll? 是否有关于在哪里选择dll的任何信息?

So I unzipped from the cab the WORDPIA.DLL on an handy directory and referenced it in my project. 因此,我从出租车上将WORDPIA.DLL解压缩到一个方便的目录中,并在我的项目中对其进行了引用。

While is it working locally, it isn't yet on the production PC. 虽然可以在本地工作,但尚未在生产PC上使用。 I'm sure I'm missing a lot of points on this topic, VS & C# are not my territory, but I need some tips to finish the project. 我确定我在这个主题上遗漏了很多观点,VS和C#不在我的领地内,但是我需要一些技巧来完成该项目。

Go back to the original project (or reference the version of the PIAs installed on your machine). 返回原始项目(或参考计算机上安装的PIA的版本)。 The redistributable is intended for installing to an Office 2010 machine where the PIAs were not installed. 可重新分发旨在用于安装到未安装PIA的Office 2010计算机上。 It's not meant to be used in the manner you envision. 并非按您设想的方式使用它。

Now click each "interop" reference entry and look at the Properties window. 现在单击每个“互操作”参考条目,然后查看“属性”窗口。 There should be a setting for "Embed Interop Types". “嵌入式互操作类型”应该有一个设置。 Set that to True. 将其设置为True。 This should make the project version-independent as it will contain the PIA information your project uses. 这应该使项目与版本无关,因为它将包含项目使用的PIA信息。

在此处输入图片说明

Note that "embed interop types" was introduced with .NET Framework 4.0 and is not available for earlier versions of the Framework. 请注意,“嵌入式互操作类型”是.NET Framework 4.0引入的,不适用于早期版本的Framework。 If an earlier version is a requirement, then you have to use late-binding or develop your project using Office 2010. 如果需要早期版本,则必须使用后期绑定或使用Office 2010开发项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM