We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to repeat a particular paragraph or Node in a word document

I have 2 Requirements


1) 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
Ex:-
Section start
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

above case i want to repeat “a” point

2) I want to repeat a particular paragraph which is in a paragraph(para in a para) all are under a section
Ex:-
Section Start
1) TO RECEIVE AND ADOPT FINANCIAL STATEMENTS FOR THE YEAR ENDED [FYE]
a. First paragraph.
b. 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.
c. Third paragraph.
#Section End
here i need to repeat “b” point


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++)
{
string text = paragraphs[i].Range.Text;
if(i==10)
// Here i need to add 10th Para to Section in both cases
}
}
Please help me how to do ?

Hi Sudheer,

Thanks for your inquiry. Please use the CompositeNode.InsertAfter method to insert the specified node immediately after the specified reference node. If refChild is null, inserts newChild at the beginning of the list of child nodes.

If the node being inserted was created from another document, you should use ImportNode to import the node to the current document. The imported node can then be inserted into the current document.

Please check the highlighted code below. In both scenarios, please use CompositeNode.InsertAfter method. I suggest you please read the members of CompositeNode from here:
http://www.aspose.com/docs/display/wordsnet/CompositeNode+Members

If you still face problem, please share your input and expected output document here for our reference. We will then provide you more information about your query along with code.


Document doc = new Document(MyDir + "Test001.docx");

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

for (int i = 0; i < paragraphs.Count; i++)

{

string text = paragraphs[i].Range.Text;

if (i == 10)

{

Paragraph para = (Paragraph)paragraphs[i].Clone(true);

((Paragraph)paragraphs[i]).ParentNode.InsertAfter(para, paragraphs[i]);

}

}

<span style=“font-size:9.5pt;line-height:200%;font-family:Consolas;mso-fareast-font-family:
“Times New Roman”;mso-ansi-language:EN-US;mso-fareast-language:EN-US;
mso-bidi-language:AR-SA”>doc.Save(MyDir + “Out.docx”);

<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>AR-SA</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–><!–[if gte mso 10]>

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin;}

<![endif]–>