繁体   English   中英

Microsoft.Office.Interop.Word程序集版本高于引用

[英]The Microsoft.Office.Interop.Word assembly version is higher than referenced

导致以下错误的原因是什么:

错误12程序集'Microsoft.Office.Interop.Word,Version = 14.0.0.0,Culture = neutral,PublicKeyToken = 71e9bce111e9429c'使用'office,Version = 14.0.0.0,Culture = neutral,PublicKeyToken = 71e9bce111e9429c',其版本高于引用程序集'office,版本= 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

我的代码:

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);

        }
    }
}

您的代码似乎引用了Office的一个版本,但尝试使用其他版本。 这是一个非常常见的问题,因为许多不同版本的Office正在使用中。

当我不得不使用Office Interop时,我通过使用Late Binding而不是Early Binding来避免这个问题。 这意味着我不添加对特定版本的Office的引用,只要我没有使用仅存在于某些版本中的函数或类似函数,我的代码将适用于任何最新版本。

本文包括基本教程,向您展示后期绑定和早期绑定之间的区别: 使用Visual C#.NET绑定Office自动化服务器

我还建议查看本文以获取更多背景信息: 在Automation中使用早期绑定和后期绑定

当我将项目从VS2005升级到VS2010时,我遇到了这个问题。 我想如果有更新的版本,Visual Studio会自动升级dll。

我取消了.dll并删除了,然后再次添加但找到了正确的版本(在本例中为12.0.0.0 )并且问题解决了。 从Bin目录中删除应该可以工作,但如果没有,在项目中搜索dll或引用名称,可能在web.config和delete中,它应该自行更新。

顺便说一下,起初我只是没有引用Office.Interop dll文件,但在它保持失败之后,我删除了一个名为office.dll的dll并再次添加,它有效。 也要找它。

祝大家好运。

我有同样的问题,从添加引用,.Net选项卡,您可以添加Microsoft.Office.Interop.Word版本= 12.0.0.0而不是Microsoft.Office.Interop.Word,版本= 14.0.0.0。 记得在此之前从References中删除版本14。 这解决了我的问题。

只是删除更高版本的互操作引用并添加使用工作的版本,然后就可以了

暂无
暂无

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

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