Primary Interop Assemblies ( PIA ) 是否需要在机器上安装 Microsoft Office 才能工作

Does Primary Interop Assemblies ( PIA ) require Microsoft Office to be installed in the machine to work

主要互操作程序集 (PIA) 是否需要在机器上安装 Microsoft Office 才能工作?

我经历了太多的迷茫post/sites,无法得出结论。

我有一台没有安装office的机器,我用的是VS2010。由于 Microsoft.Office.Interop.Excel 程序集在参考的 COM 部分不可用。我通过参考资料中的 thought .Net 部分添加了它。仍然会抛出以下错误。

Retrieving the COM class factory for component with CLSID failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))

这是来自微软网站的声明,The Office PIAs are not required on end-user computers to run Office solutions。这到底是什么意思?

这是否意味着无需安装 Office 我们就可以使用互操作程序集?

如果不是,为什么我们在需要安装 Office 才能正常工作时需要 PIA?

Does Primary Interop Assemblies ( PIA ) require Microsoft Office to be installed in the machine to work ?

是的。

PIA 只是允许您从 .NET 调用 Office COM 对象模型的程序集。由 Office 应用程序托管的 COM 对象仍然需要存在才能使其工作。 Class not registered 错误是因为计算机上缺少 COM 对象。要解决此问题,您需要安装您的应用程序适用的 Office 版本。

This is statement from Mircosoft website , The Office PIAs are not required on end-user computers to run Office solutions . What does this mean exactly ?

这不是我找到的当前报价。我找到的是:

The PIAs must also be installed on end-user computers to run Office solutions that target the .NET Framework 3.5. However, the Office PIAs are not required on end-user computers to run Office solutions that target the .NET Framework 4. For more information, see Designing and Creating Office Solutions. (https://msdn.microsoft.com/en-us/library/vstudio/hy7c6z9k(v=vs.100).aspx)

这意味着(对于 net 4+)当您使用 PIA 在 VS 中创建 Office 解决方案时,您无需在目标计算机上安装这些 PIA 即可 运行 解决方案。 (原因是,如果你的目标是 Net4,如果项目中每个 Office PIA 引用的 Embed Interop Types 属性 设置为 True(这是默认值),PIA 类型的类型信息当您构建项目时,您的解决方案使用的类型嵌入到解决方案程序集中。在 运行 时间,使用嵌入的类型信息而不是 PIA 来调用 Office 应用程序的基于 COM 的对象模型。有关更多信息有关如何将 PIA 中的类型嵌入到您的解决方案中的信息 (https://msdn.microsoft.com/en-us/library/vstudio/3295w01c(v=vs.100).aspx)

例如:我想在 VB 中编写一个程序来在 XLSX sheet 上做一些事情。

我必须在我的开发机器上安装Excel、PIA和VS,否则我将无法编写它。

此程序完成后,我希望会计部门的鲍勃 运行 它。所以我发布了程序,它安装在 Bob 的机器上。 Bob 不需要在他的本地计算机上安装 PIA 即可 运行 该程序。他 需要办公室。

Does it mean without Office installation we can work with interop assemblies ?

相反。这意味着,对于使用 PIA (EIT) 的 Net 4+ 应用程序,您的应用程序可以在客户端机器上没有安装 PIA 的情况下工作(所需的部分将成为您部署的一部分)。

你的问题其实分为两部分:

  1. 开发人员需要什么才能开发使用 Office 组件的应用程序?
  2. 最终用户 运行 该应用程序需要什么?

在 MSDN 上,文章 Office Solutions Development Overview (Visual Studio 2013) 为这些问题提供了简明的指导。来自 "Automating Office Applications by Using Primary Interop Assemblies" 部分:

You must have the Office PIAs installed and registered in the global assembly cache on your development computer to perform most development tasks. For more information, see Configuring a Computer to Develop Office Solutions. The Office PIAs are not required on end-user computers to run Office solutions. For more information, see Designing and Creating Office Solutions.

第一篇文章明确说明开发者必须安装Microsoft Office:

To create add-ins and customizations for Microsoft Office, install a supported version of Visual Studio, the .NET Framework, and Microsoft Office.

并且来自 "Understanding When the Office PIAs Are Required on End User Computers" 部分的后一篇文章:

By default, Office primary interop assemblies (PIAs) do not need to be installed on end user computers if the Embed Interop Types property of each Office PIA reference in the project is set to True, which is the default value. In this scenario, the type information for the PIA types that are used by your solution is embedded into the solution assembly when you build the project. At run time, the embedded type information is used instead of the PIAs to call into the Office application's COM-based object model. For more information about how types from PIAs are embedded into your solution, see Type Equivalence and Embedded Interop Types.