今天寫了個小程式,用.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.
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.
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.
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.
Microsoft Access 12.0 Object Library
Microsoft Office 2007 Access database engine Object Library
Microsoft.Office.Interop.Access.Dao.dll
Microsoft Excel 12.0 Object Library
Microsoft Graph 12.0 Object Library (used by PowerPoint, Access, and Word for graphs)
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 Outlook View Control (can be used in Web pages and applications to access your Inbox)
Microsoft PowerPoint 12.0 Object Library
Microsoft Publisher 12.0 Object Library
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 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 12.0 Object Library (Office shared functionality)
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
<b>如何:通過主互操作程式集面向</b><b> Office </b><b>應用程式</b><b></b>
在 Visual Studio 中建立新的 Visual Studio Tools for Office 項目時,如果已經在計算機的全局程式集緩存 (GAC) 中安裝了正确的主互操作程式集 (PIA),則會在項目中自動添加對該程式集的引用。若要使用托管代碼使其他 Microsoft Office 應用程式的功能自動化,則必須手動添加對相應元件的引用。
<b>添加對主互操作程式集的引用</b><b></b>
1. 打開 Visual Studio Tools for Office 項目,并在“解決方案資料總管”中選擇該項目名稱。
2. 打開“項目”菜單,然後單擊“添加引用”。
4. 單擊“确定”。
該元件名稱即出現在“解決方案資料總管”的“引用”檔案夾中。
<b>請參見</b><b></b>
<b>任務</b><b></b>
<a href="http://msdn.microsoft.com/zh-cn/library/kh3965hw(VS.80).aspx">如何:安裝 Office 主互操作程式集</a>
<a href="http://msdn.microsoft.com/zh-cn/library/4eb92bst(VS.80).aspx">如何:使用主互操作程式集使 Office 應用程式自動化</a>
<b>其他資源</b><b></b>
<a href="http://msdn.microsoft.com/zh-cn/library/e7ezs44a(VS.80).aspx">對 Office 應用程式進行程式設計</a>
<a href="http://msdn.microsoft.com/zh-cn/library/y1xatbkd(VS.80).aspx">使用 Office 對象模型實作應用程式自動化</a>
本文轉自斯克迪亞部落格園部落格,原文連結:http://www.cnblogs.com/sgsoft/archive/2009/02/07/1385919.html,如需轉載請自行聯系原作者