[英]Create a Word document with C#?
I'm trying to create a Word document with C# in visual studio 2008, this is my code: 我试图在Visual Studio 2008中使用C#创建Word文档,这是我的代码:
using Word = Microsoft.Office.Interop.Word;
Word.Application oWord = new Word.Application();
oWord.Visible = true;
Visual studio shows me the error: Visual Studio向我显示了错误:
Invalid token '=' in class, struct, or interface member declaration
类,结构或接口成员声明中的无效令牌“ =”
Why does this happen? 为什么会这样?
您的代码必须在方法内部,而不是在方法外部的类定义中。
It should look something like this: 它看起来应该像这样:
using Word = Microsoft.Office.Interop.Word;
namespace TestApp
{
public partial class MainWindow : Window
{
public MainWindow()
{
Word.Application oWord = new Word.Application();
oWord.Visible = true;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.