質問

In my Requirement i want to repeat a particular paragraph which is in section in a word document. here word document divided into sections, in sections we have paragraphs like below

#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

i want to repeat "a" point into 3 times

i tried the below code

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

                    }
                  }

Please help me how to repeat a paragraph.

役に立ちましたか?

解決

I am working as Social Media Developer at Aspose. Please use the following sample code to repeat a paragraph using 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");
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top