.NET ASP.NET中名称空间Microsoft.Office.Interop.Word的异常解析

时间:2016-12-01 10:28:45

标签: c# asp.net .net namespaces

使用库

处理C#ASP.NET应用程序
 Dim output As String = Nothing
            For Each Word As String In UserInput.Split(CChar(" "))
                output &= (words.IndexOf(Word) + 1).ToString & ", "
            Next
            Label1.Text = output.Substring(0, output.Length - 2)

如果我使用以下方式添加:

Microsoft.Office.Interop.Word

VS可以using Microsoft.Office.Interop.Word;

正确解析Application

但它无法解决

Microsoft.Office.Interop.Word.Application

我必须写完整的路径:

Word.WdSaveFormat.wdFormatDocumentDefault

我需要编写以下额外的include行来让VS解决后者:

Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocumentDefault

你能给我一个解释吗?

THX

2 个答案:

答案 0 :(得分:0)

Word.WdSaveFormat.wdFormatDocumentDefault不在命名空间Microsoft.Office.Interop.Word中。它位于Microsoft.Office.Interop。把它放在一个使用条款中,你应该好好去。

using Microsoft.Office.Interop;

答案 1 :(得分:0)

实际上你只需要定义第一行

using Word = Microsoft.Office.Interop.Word;

“Word”实际上是名称空间别名,而Microsoft.Office.Interop.Word不是库,它实际上是一个对象。此外,因为它是一个别名,你可以使用任何名称,所以像:

using W = Microsoft.Office.Interop.Word;

也是有效的,但您必须在代码上使用该命名空间,例如:

W.WdSaveFormat.wdFormatDocumentDefault