【问题标题】:Create a Word document with C#?用 C# 创建 Word 文档?
【发布时间】:2012-07-26 10:32:09
【问题描述】:

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

using Word = Microsoft.Office.Interop.Word;

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

Visual Studio 向我显示错误:

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

为什么会这样?

【问题讨论】:

  • 在哪一行?粘贴所有代码...
  • 在 oWord.Visible = true 行中;
  • 我再问一次 - 粘贴您的所有代码。该文件中的每一行。

标签: c# reference ms-word


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    它应该看起来像这样:

    using Word = Microsoft.Office.Interop.Word;
    
    
    namespace TestApp
    {
        public partial class MainWindow : Window
        {
    
            public MainWindow()
            {
                Word.Application oWord = new Word.Application();
                oWord.Visible = true;
            }
    
    
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多