今天写了个小程序,用.NET操作Office模板文件,生成期望的Word文件。开发环境运行正常,可放到另一台机器上就不好用,提示找不到COM….

确认目标机器安装了Office,而且版本和开发环境一样,唯一的差别是目标机器没有安装VS,在目标机器上Refactor一下程序,马上发现是找不到Microsoft.Office.Interop.Word.dll .

安装Office PIA后问题解决。后来发现目标机器安装的是Office所谓的精简版,原因明了。

Office PIA实际就是Office 的.NET编程支持,安装之后,会在VS的COM列表中出现Office类型库,而不是在.NET组件中显示。

参考内容:

Visual Studio Tools for the Microsoft Office System

Office Primary Interop Assemblies

When you create a new Visual Studio Tools for Office project, a reference to the correct primary interop assembly (PIA) is added to your project automatically if the assembly is installed in the Windows global assembly cache (GAC). The Microsoft Office primary interop assemblies are installed in the global assembly cache during a Complete installation.

For more information about primary interop assemblies, see Primary Interop Assemblies and the MSDN article "Primary Interop Assemblies (PIAs)" (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/whypriinterop.asp).

 Applications That Do Not Have Projects in Visual Studio Tools for Office

For Microsoft Office applications that do not have projects in Visual Studio Tools for Office, you must add a reference to the appropriate application or component to your project manually. Adding a reference to the component references the primary interop assembly, if the assembly is installed in the global assembly cache. Office applications and components are accessible from the COM tab of the Add Reference dialog box.

If the primary interop assembly is not installed in the global assembly cache, Visual Studio generates an interop assembly for the project that might not work fully in all cases. For more information, see Troubleshooting in Office at Run Time.

Note

Some assemblies are added to a project automatically when an assembly that references them is added. For example, references to the assemblies Office.dll and Microsoft.Vbe.Interop.dll are added automatically when you add a reference to the Word, Excel, Outlook, Microsoft Forms, or Graph assemblies.

For more information about installing Office primary interop assemblies, see How to: Install Office Primary Interop Assemblies. For more information about adding references, see How to: Add and Remove References in Visual Studio (C#, J#).

 Available Assemblies for Microsoft Office 2003

The following table shows primary interop assemblies that are available to install with Microsoft Office 2003.

Office Application or Component 
Primary Interop Assembly Name

Microsoft Access 11.0 Object Library

Microsoft.Office.Interop.Access.dll

Microsoft Excel 11.0 Object Library

Microsoft.Office.Interop.Excel.dll

Microsoft FrontPage 6.0 Web Object Reference Library

Microsoft.Office.Interop.Frontpage.dll

Microsoft FrontPage 6.0 Page Object Reference Library

Microsoft.Office.Interop.Frontpageeditor.dll

Microsoft Graph 11.0 Object Library (used by PowerPoint, Access, and Word for graphs)

Microsoft.Office.Interop.Graph.dll

Microsoft Outlook 11.0 Object Library

Microsoft.Office.Interop.Outlook.dll

Microsoft Outlook View Control (can be used in Web pages and applications to access your Inbox)

Microsoft.Office.Interop.OutlookViewCtl.dll

Microsoft Office Web Components 11.0 (spreadsheet, graph, and pivot table for Web pages)

Microsoft.Office.Interop.owc11.dll

Microsoft PowerPoint 11.0 Object Library

Microsoft.Office.Interop.PowerPoint.dll

Microsoft Publisher 11.0 Object Library

Microsoft.Office.Interop.Publisher.dll

Microsoft Smart Tags 2.0 Type Library

Microsoft.Office.Interop.SmartTag.dll

Microsoft Word 11.0 Object Library

Microsoft.Office.Interop.Word.dll

Microsoft Visual Basic for Applications Extensibility 5.3

Microsoft.Vbe.Interop.dll

Microsoft Forms 2.0 Object Library (programmable controls that can be used in applications)

Microsoft.Vbe.Interop.Forms.dll

Microsoft Office 11.0 Object Library (Office shared functionality)

office.dll

 Available Assemblies for the 2007 Microsoft Office System

The following table shows primary interop assemblies that are available to install with the 2007 Microsoft Office system.

Office Application or Component 
Primary Interop Assembly Name

Microsoft Access 12.0 Object Library

Microsoft.Office.Interop.Access.dll

Microsoft Office 2007 Access database engine Object Library

Microsoft.Office.Interop.Access.Dao.dll

Microsoft Excel 12.0 Object Library

Microsoft.Office.Interop.Excel.dll

Microsoft Graph 12.0 Object Library (used by PowerPoint, Access, and Word for graphs)

Microsoft.Office.Interop.Graph.dll

Microsoft InfoPath 2.0 Type Library

Microsoft.Office.Interop.InfoPath.dll

Microsoft InfoPath XML Interop Assembly

Microsoft.Office.Interop.InfoPath.Xml.dll

Microsoft Outlook 12.0 Object Library

Microsoft.Office.Interop.Outlook.dll

Microsoft Office Outlook View Control (can be used in Web pages and applications to access your Inbox)

Microsoft.Office.Interop.OutlookViewCtl.dll

Microsoft PowerPoint 12.0 Object Library

Microsoft.Office.Interop.PowerPoint.dll

Microsoft Publisher 12.0 Object Library

Microsoft.Office.Interop.Publisher.dll

Microsoft SharePointDesigner 12.0 Web Object Reference Library

Microsoft.Office.Interop.SharePointDesigner.dll

Microsoft SharePointDesigner 12.0 Page Object Reference Library

Microsoft.Office.Interop.SharePointDesignerPage.dll

Microsoft Smart Tags 2.0 Type Library

Microsoft.Office.Interop.SmartTag.dll

Microsoft Visio 12.0 Type Library

Microsoft.Office.Interop.Visio.dll

Microsoft Visio 12.0 Save As Web Type Library

Microsoft.Office.Interop.Visio.SaveAsWeb.dll

Microsoft Visio 12.0 Drawing Control Type Library

Microsoft.Office.Interop.VisOcx.dll

Microsoft Word 12.0 Object Library

Microsoft.Office.Interop.Word.dll

Microsoft Visual Basic for Applications Extensibility 5.3

Microsoft.Vbe.Interop.dll

Microsoft Office 12.0 Object Library (Office shared functionality)

office.dll

Binding Redirect Assembly for Microsoft Access Object Library

Policy.11.0.Microsoft.Office.Interop.Access.dll

Binding Redirect Assembly for Microsoft Excel Object Library

Policy.11.0.Microsoft.Office.Interop.Excel.dll

Binding Redirect Assembly for Microsoft Graph Object Library

Policy.11.0.Microsoft.Office.Interop.Graph.dll

Binding Redirect Assembly for Microsoft InfoPath Type Library

Policy.11.0.Microsoft.Office.Interop.InfoPath.dll

Binding Redirect Assembly for Microsoft InfoPath XML Interop Assembly

Policy.11.0.Microsoft.Office.Interop.InfoPath.Xml.dll

Binding Redirect Assembly for Microsoft Outlook Object Library

Policy.11.0.Microsoft.Office.Interop.Outlook.dll

Binding Redirect Assembly for Microsoft Outlook View Control

Policy.11.0.Microsoft.Office.Interop.OutlookViewCtl.dll

Binding Redirect Assembly for Microsoft PowerPoint Object Library

Policy.11.0.Microsoft.Office.Interop.PowerPoint.dll

Binding Redirect Assembly for Microsoft Publisher Object Library

Policy.11.0.Microsoft.Office.Interop.Publisher.dll

Binding Redirect Assembly for Microsoft Smart Tags Type Library

Policy.11.0.Microsoft.Office.Interop.SmartTag.dll

Microsoft Visio Type Library

Policy.11.0.Microsoft.Office.Interop.Visio.dll

Binding Redirect Assembly for Microsoft Visio Save As Web Type Library

Policy.11.0.Microsoft.Office.Interop.Visio.SaveAsWeb.dll

Binding Redirect Assembly for Microsoft Visio Drawing Control Type Library

Policy.11.0.Microsoft.Office.Interop.VisOcx.dll

Binding Redirect Assembly for Microsoft Word Object Library

Policy.11.0.Microsoft.Office.Interop.Word.dll

Binding Redirect Assembly for Microsoft Visual Basic for Applications Extensibility 5.3

Policy.11.0.Microsoft.Vbe.Interop.dll

Binding Redirect Assembly for Microsoft Office Object Library

Policy.11.0.office.dll

Note

The binding redirect assemblies help make sure that the 2007 Microsoft Office version of the primary interop assemblies are loaded at run time. When a Visual Studio Tools for Office solution that references a Microsoft Office 2003 primary interop assembly runs on a computer that has the 2007 Microsoft Office version of the same primary interop assembly, the binding redirect assembly instructs the .NET Framework runtime to load the 2007 Microsoft Office version of the primary interop assembly. For more information, see Assembly Binding Redirection.   From:http://msdn.microsoft.com/en-us/library/15s06t57(VS.80).aspx

参考内容:

如何:通过主互操作程序集面向 Office 应用程序

在 Visual Studio 中创建新的 Visual Studio Tools for Office 项目时,如果已经在计算机的全局程序集缓存 (GAC) 中安装了正确的主互操作程序集 (PIA),则会在项目中自动添加对该程序集的引用。若要使用托管代码使其他 Microsoft Office 应用程序的功能自动化,则必须手动添加对相应组件的引用。

注意

显示的对话框和菜单命令可能会与“帮助”中的描述不同,具体取决于您的当前设置或版本。若要更改设置,请在“工具”菜单上选择“导入和导出设置”。有关更多信息,请参见 Visual Studio 设置。

添加对主互操作程序集的引用

1. 打开 Visual Studio Tools for Office 项目,并在“解决方案资源管理器”中选择该项目名称。

2. 打开“项目”菜单,然后单击“添加引用”。

3. 在“COM”选项卡下,在“组件名称”列表中选择所需的组件。有关 Microsoft Office 主互操作程序集和相应组件名称的列表,请参见 Office 主要互操作程序集。

4. 单击“确定”。

该组件名称即出现在“解决方案资源管理器”的“引用”文件夹中。

如果该主互操作程序集没有安装在全局程序集缓存中或者无法访问,Visual Studio 将为该项目生成一个互操作程序集,但该程序集不一定能在所有情况下工作。如果发生这种情况,Visual Studio 将在该项目的文件夹而非全局程序集缓存中创建该程序集。可以在 Visual Studio 的“属性”窗口中检查该程序集的“路径”属性,以查找该程序集的位置。有关更多信息,请参见 Office 运行时的疑难解答中的“无法初始化程序集”。

请参见

任务

如何:安装 Office 主互操作程序集
如何:使用主互操作程序集使 Office 应用程序自动化

其他资源

对 Office 应用程序进行编程
使用 Office 对象模型实现应用程序自动化

本文转自斯克迪亚博客园博客,原文链接:http://www.cnblogs.com/sgsoft/archive/2009/02/07/1385919.html,如需转载请自行联系原作者

关于.NET操作Office(Office PIA)相关推荐

  1. Excel操作 Microsoft.Office.Interop.Excel.dll的使用

    原文地址为: Excel操作 Microsoft.Office.Interop.Excel.dll的使用 先说说题外话,前段时间近一个月,我一直在做单据导入功能,其中就涉及到Excel操作,接触Exc ...

  2. java poi word宏_全面了解POI操作Microsoft Office(Word、Excel、PowerPoint)

    POI 与 Microsoft Office 1. POI 简介 POI 是 Apache 下的 Jakata 项目的一个子项目,主要用于提供 java 操作 Microsoft Office 办公套 ...

  3. 数据转换excel操作 Microsoft.Office.Interop.Excel.dll的使用

    引用:http://www.cnblogs.com/lanjun/archive/2012/06/17/2552920.html 先说说题外话,前段时间近一个月,我一直在做单据导入功能,其中就涉及到E ...

  4. 【转载】Excel操作 Microsoft.Office.Interop.Excel.dll的使用

    http://www.cnblogs.com/lanjun/archive/2012/06/17/2552920.html 先说说题外话,前段时间近一个月,我一直在做单据导入功能,其中就涉及到Exce ...

  5. [系统操作][MS Office]Excel在无任何操作的前提下关闭文档却询问是否保存

    起因 之前朋友写了一个EXCEL插件,希望我能够帮他解决一下里面的一个问题.此事过去几天后,无意中发现在没有进行任何操作的情况下,EXCEL对于文档进行关闭时询问是否保存.然后发现,对于一个新创建的文 ...

  6. Windows10(64位)的操作系统安装Office(64位)提示无法安装

    Q:Windows10 64位操作系统安装64位的Office出现如下图提示: R:其原因是之前安装的32位程序没有完全删除掉,我们需要到注册表中删掉相应注册表信息 S:解决方案步骤如下: 1.键盘[ ...

  7. 【软件操作】Office将Word文档转换为PDF格式

    一.问题描述 PDF格式(Portable Document Format)相比于Word文档(.doc/.docx格式)体积更大,但具有更好的文档一致性(减少排版问题),修改更困难(不易被外界篡改) ...

  8. 打开office显示无法执行此操作,因为office未能识别操作给定命令

    今年第一次打开就遇见了这种情况,打开word.PPT.Excel什么都不行,我还以为我要重装!好在我偶然成功打开. 一步搞定--删掉WPS Office!!!

  9. Office办公软件操作技巧 office快捷键大全

    ››››F键 F1:显示「帮助」任务窗格. F2+shift:添加或编辑单元格批注 F3+shift:显示「插入函数」对话框 F4:重复上一个命令或操作 F5+G:显示「定位」对话框 F9+ctrl: ...

  10. android办公软件office,Office办公助手(安卓手机office办公软件)V1.5.1 极限精简版

    Office办公助手(安卓手机office办公软件)专为办公室白领以及商务人士设计,提供最高效并且易用的移动办公功能,来协助您处理日常的移动办公.并且拥有几百万用户好评的功能,相信也正是您所需要的. ...

最新文章

  1. python控制git版本库
  2. mysql主从复制、redis基础、持久化和主从复制
  3. STL容器之Deque-《C++标准库(第二版)》读书笔记
  4. 【计算广告】不懂这些专业术语别说你懂广告
  5. k8s节点亲和性:pod和node的亲和性、硬策略、软策略
  6. 算法优化:最大子段和,最大子矩阵和,一维,二维情况分析,动态规划
  7. How to change max_allowed_packet size
  8. python 远程控制_用 Python 远程控制你的电脑
  9. 细胞自动机 c语言程序,Processing精彩例程之细胞自动机
  10. 人有多大懒,才有多大闲 (评论『卓有成效的程序员』)
  11. MySQL大批量造数据
  12. linux 三网卡 双网关,三网卡双机互联共享Internet
  13. 【Microsoft Office】免密破解Microsoft Word文档(.docx)的文档保护
  14. 架构师之路-秒杀系统优化思路
  15. 东华大学计算机考研大纲,2019年东华大学854计算机及软件工程专业基础综合考研初试大纲...
  16. 因为这个原因,将谷歌浏览器更换到国产浏览器
  17. Leetcode题目分类指南(单独刷题或学习算法书籍配合使用)
  18. PY32 单片机离线烧录器使用说明
  19. 通俗易懂解释汉明码(附MATLAB实现代码)
  20. SpringBoot整合Elastricsearch + LogStash + Kibana太简单了!

热门文章

  1. 全日制本科生入户东莞指南
  2. 浪潮信息的ai服务器有何不同,浪潮信息AI服务器NF5468M6、NF5468A5成ISC20大会焦点...
  3. ros发布和订阅图像的压缩——高效图传(适用带宽不足问题)
  4. docker管理mysql风险_不要再问了,数据库不建议上Docker
  5. html中根号怎么写,HTML特殊符号对应代码
  6. 彻底卸载智能云输入法(在win10家庭版下)
  7. 区块链除了炒币,还可以做什么?
  8. Python 教程:eval()和exac()详细用法以及区别
  9. Ubuntu 经验 :系统安装 :分区方案
  10. Android初学者仿QQ聊天软件APP (一) 登录界面