我正在尝试使用Microsoft Office Interops版本11,.NET 2.0修复使用Visual Studio 2003创建的旧版应用程序。我正在尝试在Visual Studio Express 2010中修复它以引用Interops版本14,.NET 4.0 - 正如我之前关于StackOverflow的问题中所述,遗留应用程序在Windows 7中运行良好但在关闭它之后,Microsoft Office产品是当我尝试使用它们时崩溃。
但是,当我修复VS2010中的引用(删除旧的v.11 Interops,添加新的v.14 Interops)然后尝试发布应用程序时,我收到错误,如
'Microsoft.Office.Interop.Word.System does not contain a definition for IO'
看起来VS2010在引用Word命名空间时没有看到我的系统名称空间被使用?当我删除
using Microsoft.Office.Interop.Word
命名空间然后尝试发布,上面的错误消失了,我只得到与缺少的Word引用相关的预期错误,如
The type or namespace name '_Document' could not be found (are you missing a using directive or an assembly reference?)
我已将System.dll包含在参考中,所以我不确定发生了什么?谢谢你的阅读!
编辑:我为Office Interops设置了“Embeded Interop Types”。那可能修复了一些错误?但是:Visual Studio仍然将任何系统引用解释为“Microsoft.Office.Interop.Word.System”,这不是我想要的。这个错误现在似乎是主导的:The type name 'Windows' does not exist in the type 'Microsoft.Office.Interop.Word.System'
答案 0 :(得分:5)
这个问题发生在我身上,只有当我把这些东西放在命名空间定义之后才会这样:
namespace Addin
{
using Microsoft.Office.Core;
using Microsoft.Office.Interop.Word;
using Microsoft.Win32;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Net;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows.Forms;
..........................
正确的方法是:
using Microsoft.Office.Core;
using Microsoft.Office.Interop.Word;
using Microsoft.Win32;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Net;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace Addin
{
....................
它可以帮助你!
答案 1 :(得分:0)
要修复名称空间中的问题:
变化:
using Microsoft.Office.Interop.Word;
为:
using Document = Microsoft.Office.Interop.Word.Document;
对于您可能正在使用的任何其他冲突命名空间的其他对象执行相同的操作。