【问题标题】:How to repeat a paragraph which is in a section using ASPOSE.DLL如何使用 ASPOSE.DLL 重复段落中的段落
【发布时间】:2014-05-14 04:40:46
【问题描述】:

在我的要求中,我想重复一个特定的段落,该段落位于 word 文档的部分中。 这里的word文档分为几个部分,在部分我们有如下段落

#Section Start
1) TO RECEIVE AND ADOPT FINANCIAL STATEMENTS FOR THE YEAR ENDED [FYE]

a.That the Financial Statements of the Company for the financial year ended [FYE] together    with the Director(s)' Report and Statement thereon be hereby received and adopted.
b. Second paragraph.
c. Third paragraph.
#Section End

我想把“a”点重复3次

我试过下面的代码

 // Copy all content including headers and footers from the specified 
 //pages into the   destination document.
                ArrayList pageSections = finder.RetrieveAllNodesOnPages(1, doc.Sections.Count, NodeType.Section);
                System.Data.DataTable dt = GetDataTable(); //Sample DataTable which is having Keys and Values
                int sectionCount = 0;
                foreach (Section section in pageSections)
                {

                    NodeCollection paragraphs =    section.GetChildNodes(NodeType.Paragraph, true);

                    for (int i = 0; i < paragraphs.Count; i++)
                    {
                        string text = paragraphs[i].Range.Text;

                    }
                  }

请帮助我如何重复一段。

【问题讨论】:

    标签: asp.net aspose aspose.words


    【解决方案1】:

    我在 Aspose 担任社交媒体开发人员。请使用以下示例代码使用 Aspose.Words for .NET 重复一个段落。

    Document doc = new Document("document.docx");
    
    PageNumberFinder finder = new PageNumberFinder(doc);
    
    // Split nodes which are found across pages.
    finder.SplitNodesAcrossPages(true);
    
    // Copy all content including headers and footers from the specified pages into the                                 
    //destination document.
    ArrayList pageSections = finder.RetrieveAllNodesOnPages(1, doc.Sections.Count, NodeType.Section);
    
    //Sample DataTable which is having Keys and Values
    System.Data.DataTable dt = GetDataTable();
    
    int sectionCount = 0;
    
    foreach (Section section in pageSections)
    {
    
        NodeCollection paragraphs = section.GetChildNodes(NodeType.Paragraph, true);
    
        for (int i = 0; i < paragraphs.Count; i++)
        {                    
            //Paragraph you want to copy
            if (i == 10)
            {
    
                //Use Document Builder to Navigate to the paragraph
                DocumentBuilder builder = new DocumentBuilder(doc);
    
                builder.MoveTo(paragraphs[i]);
    
                //Insert a Paragraph break
                builder.InsertParagraph();
    
                //Insert the Paragraph to repeat it
                builder.Writeln(paragraphs[i].ToString(SaveFormat.Text)); 
    
    
            }
    
    
        }
    
    }
    
    doc.Save("test.docx");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-22
      • 2021-10-12
      • 2022-08-04
      • 1970-01-01
      • 2021-10-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-17
      相关资源
      最近更新 更多