该组装的Microsoft.Office.Interop.Word版本高于参考 [英] The Microsoft.Office.Interop.Word assembly version is higher than referenced
问题描述
什么是以下错误的原因:
错误12大会'的Microsoft.Office.Interop.Word,版本= 14.0。 0.0,
区域性=中性公钥= 71e9bce111e9429c'使用'的办公室,
版本= 14.0.0.0,文化=中性公钥= 71e9bce111e9429c'
具有更高版本比引用的程序集的办公室,
版本= 12.0.0.0,文化=中立,
公钥= 71e9bce111e9429c'C:\Program Files\Microsoft视觉
工作室10.0\Visual Studio工具
厅\PIA\Office14\Microsoft.Office.Interop.Word.dll WindowsFormsApplication1
块引用>
我的代码:
<预类=郎-CS prettyprint-覆盖>使用系统;
使用System.Collections.Generic;
使用System.ComponentModel;
使用System.Data这;
使用System.Drawing中;
使用System.Linq的;
使用的System.Reflection;
使用System.Text;使用System.Windows.Forms的
;
使用的Microsoft.Office.Interop.Word;使用应用= Microsoft.Office.Interop.Word.Application
;使用数据表= System.Data.DataTable
;使用文档= Microsoft.Office.Interop.Word.Document
;
使用Microsoft.Office;
命名空间WindowsFormsApplication1
{
公共部分Form1类:表格
{
公共Form1中()
{
的InitializeComponent() ;
}
私人无效Form1_Load的(对象发件人,EventArgs五)
{
变种wordApp =新的应用程序{可见= FALSE};
对象objMissing = Missing.Value;
文档wordDoc = wordApp.Documents.Add(REF objMissing,裁判objMissing,裁判objMissing,裁判objMissing);
wordApp.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekCurrentPageFooter;
wordApp.Selection.TypeParagraph();
字符串docNumber =1;
字符串revisionNumber =0;
wordApp.Selection.Paragraphs.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
wordApp.ActiveWindow.Selection.Font.Name =宋体;
wordApp.ActiveWindow.Selection.Font.Size = 8;
wordApp.ActiveWindow.Selection.TypeText(文件编号:+ docNumber + - 修订#:+ revisionNumber);
wordApp.ActiveWindow.Selection.TypeText(\t);
wordApp.ActiveWindow.Selection.TypeText(\t);
wordApp.ActiveWindow.Selection.TypeText(页面);
对象当前页= WdFieldType.wdFieldPage;
wordApp.ActiveWindow.Selection.Fields.Add(wordApp.Selection.Range,参考当前页,参考objMissing,裁判objMissing);
wordApp.ActiveWindow.Selection.TypeText(的);
对象总页数= WdFieldType.wdFieldNumPages;
wordApp.ActiveWindow.Selection.Fields.Add(wordApp.Selection.Range,楼盘总页数,裁判objMissing,裁判objMissing);
wordApp.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekMainDocument;
对象C =D:\\1.doc
wordDoc.Paragraphs.LineSpacing = 8;
款WP = wordDoc.Paragraphs.Add(REF objMissing);
wp.Range.Text + = richTextBox1.Text;
wordDoc.SaveAs(REF C,裁判objMissing,裁判objMissing,裁判objMissing,裁判objMissing,裁判objMissing,
裁判objMissing
,裁判objMissing,裁判objMissing,REF objMissing, REF objMissing,裁判objMissing,
裁判objMissing,裁判objMissing
,裁判objMissing,裁判objMissing);
(wordDoc).Close(REF objMissing,裁判objMissing,裁判objMissing);
(wordApp).Quit(REF objMissing,裁判objMissing,裁判objMissing);
}
}
}
解决方案这似乎是你的代码的参考版本的Office,但正试图用一个不同的版本。这是一个相当普遍的问题,因为有很多不同版本的Office都在使用。
当我不得不使用Office互操作,我避免此问题,通过使用
后期绑定
,而不是早期绑定
。这意味着,我不添加引用Office的特定版本,我的代码将与任何最新版本,只要我不使用功能或类似的,只有在某些版本存在的工作。
本文包含的基本教程向您展示后期和早期绑定的区别:绑定办公自动化使用Visual C#.NET
服务器
我还建议在看这篇文章的更多背景信息:的Using~~V早期绑定和自动化
后期绑定What is the cause of the following error:
Error 12 Assembly 'Microsoft.Office.Interop.Word, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' uses 'office, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' which has a higher version than referenced assembly 'office, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' c:\Program Files\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office14\Microsoft.Office.Interop.Word.dll WindowsFormsApplication1
my code :
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Reflection; using System.Text; using System.Windows.Forms; using Microsoft.Office.Interop.Word; using Application = Microsoft.Office.Interop.Word.Application; using DataTable = System.Data.DataTable; using Document = Microsoft.Office.Interop.Word.Document; using Microsoft.Office; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { var wordApp = new Application { Visible = false }; object objMissing = Missing.Value; Document wordDoc = wordApp.Documents.Add(ref objMissing, ref objMissing, ref objMissing, ref objMissing); wordApp.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekCurrentPageFooter; wordApp.Selection.TypeParagraph(); String docNumber = "1"; String revisionNumber = "0"; wordApp.Selection.Paragraphs.Alignment = WdParagraphAlignment.wdAlignParagraphLeft; wordApp.ActiveWindow.Selection.Font.Name = "Arial"; wordApp.ActiveWindow.Selection.Font.Size = 8; wordApp.ActiveWindow.Selection.TypeText("Document #: " + docNumber + " - Revision #: " + revisionNumber); wordApp.ActiveWindow.Selection.TypeText("\t"); wordApp.ActiveWindow.Selection.TypeText("\t"); wordApp.ActiveWindow.Selection.TypeText("Page "); Object CurrentPage = WdFieldType.wdFieldPage; wordApp.ActiveWindow.Selection.Fields.Add(wordApp.Selection.Range, ref CurrentPage, ref objMissing, ref objMissing); wordApp.ActiveWindow.Selection.TypeText(" of "); Object TotalPages = WdFieldType.wdFieldNumPages; wordApp.ActiveWindow.Selection.Fields.Add(wordApp.Selection.Range, ref TotalPages, ref objMissing, ref objMissing); wordApp.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekMainDocument; object c = "d:\\1.doc"; wordDoc.Paragraphs.LineSpacing = 8; Paragraph wp = wordDoc.Paragraphs.Add(ref objMissing); wp.Range.Text += richTextBox1.Text; wordDoc.SaveAs(ref c, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing , ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing , ref objMissing, ref objMissing); (wordDoc).Close(ref objMissing, ref objMissing, ref objMissing); (wordApp).Quit(ref objMissing, ref objMissing, ref objMissing); } } }
解决方案It seems like your code reference one version of Office, but is trying to use a different version. This is quite a common issue since a lot of different versions of Office are in use.
When I've had to use Office Interop, I avoid this issue by using
Late Binding
rather thanEarly Binding
. This means that I don't add a reference to a specific version of Office and my code will work with any recent version as long as I'm not using a function or similar that only exist in certain versions.This article includes basic tutorials to show you the difference between late and early binding: Binding for Office automation servers with Visual C# .NET
I'd also suggest looking at this article for more background information: Using early binding and late binding in Automation
这篇关于该组装的Microsoft.Office.Interop.Word版本高于参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!