0

我正在尝试在 Visual Studio 2008 中使用 C# 创建 Word 文档,这是我的代码:

using Word = Microsoft.Office.Interop.Word;

Word.Application oWord = new Word.Application();
oWord.Visible = true;

Visual Studio 向我显示错误:

类、结构或接口成员声明中的标记“=”无效

为什么会这样?

4

2 回答 2

3

您的代码必须在方法内部,而不是在方法之外的类定义中。

于 2012-07-26T10:37:31.470 回答
0

它应该看起来像这样:

using Word = Microsoft.Office.Interop.Word;


namespace TestApp
{
    public partial class MainWindow : Window
    {

        public MainWindow()
        {
            Word.Application oWord = new Word.Application();
            oWord.Visible = true;
        }


    }
}
于 2012-07-26T10:51:56.423 回答