2012-07-26 108 views
0

我試圖創建一個C#在Visual Studio 2008中的Word文檔,這是我的代碼:用C#創建一個Word文檔?

using Word = Microsoft.Office.Interop.Word; 

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

Visual Studio中顯示我的錯誤:

Invalid token '=' in class, struct, or interface member declaration

爲什麼會出現這種情況?

+1

在哪條線路?粘貼你的所有代碼... – tomfanning 2012-07-26 10:33:03

+0

在行oWord.Visible = true; – user1523566 2012-07-26 10:43:42

+0

我再問一遍 - 粘貼你的所有代碼。該文件中的每一行。 – tomfanning 2012-07-26 11:49:40

回答

3

您的代碼必須在方法內,而不是在方法外的類定義中。

+0

好的非常感謝! – user1523566 2012-07-26 11:52:02

+0

不客氣。 – 2012-07-26 11:52:52

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; 
     } 


    } 
}