【问题标题】:Copy content of word document Sections复制word文档部分的内容
【发布时间】:2019-06-19 16:26:27
【问题描述】:

在我的应用程序中,我使用 Microsoft.Office.Interop.Word 将内容写入 Word 文档。

        var wordApplication = new Word.Application { Visible = true };
        var document = wordApplication.Documents.Add();
        document.Activate();

每隔 1 分钟,我将在文档的新部分中写几行。 即每5分钟开始在word文档中添加一个新部分并将光标移动到该部分,然后写入内容。

        document.Sections.Add();
        wordApplication.ActiveWindow.Selection.GoTo(Word.WdGoToItem.wdGoToPage, Word.WdGoToDirection.wdGoToLast);

每 10 分钟后,我需要在后台运行一个线程并将每个部分中可用的内容复制到远程位置的不同文本文件中。

我的问题是,我无法访问各个部分。 建议一种方法将每个部分中的文本复制到单独的变量或数组中。

【问题讨论】:

    标签: c# .net ms-word


    【解决方案1】:

    这对我有用:

        System.Collections.ArrayList al = new System.Collections.ArrayList();
    
        int mycount = 0;
    
        foreach (Microsoft.Office.Interop.Word.Section section in document.Sections)
    
        {
    
            al.Insert(mycount, section.Range.Text.ToString());
    
            mycount++;
    
        }     
    
         mycount = 0;
    
         while (mycount < al.Count)
    
         {
    
            MessageBox.Show(" Section Text " + al[mycount].ToString());
    
           mycount++;
    
         }
    

    【讨论】:

      猜你喜欢
      • 2018-07-29
      • 1970-01-01
      • 2010-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多