我正在尝试在 Visual Studio 2008 中使用 C# 创建 Word 文档,这是我的代码:
using Word = Microsoft.Office.Interop.Word;
Word.Application oWord = new Word.Application();
oWord.Visible = true;
Visual Studio 向我显示错误:
类、结构或接口成员声明中的标记“=”无效
为什么会这样?
您的代码必须在方法内部,而不是在方法之外的类定义中。
它应该看起来像这样:
using Word = Microsoft.Office.Interop.Word;
namespace TestApp
{
public partial class MainWindow : Window
{
public MainWindow()
{
Word.Application oWord = new Word.Application();
oWord.Visible = true;
}
}
}