Free Support Forum - aspose.com

How to change CurrentSection text

Hi

I want to change text of CurrentSection.
Here is a method to get text: Builder.CurrentSection.GetText();
Is there any method to change or replace current text with new text?

Also i use bellow code:
Builder.CurrentSection.Range.Replace(oldText, NewText, false, false);

but it not work correctly in all case. For example when oldText contain special character like \f or \r.

Hi Saeed,


Thanks for your inquiry. If you want to replace complete section’s contents, please use the following code snippet. The following code example removes all nodes of Section.Body and insert new text by using DocumentBuilder.Writeln method. Hope this helps you. Please let us know if you have any more queries.


Document doc = new
Document(MyDir + “in.docx”);<o:p></o:p>

DocumentBuilder builder = new DocumentBuilder(doc);

Section section = builder.CurrentSection;

section.Body.RemoveAllChildren();

Paragraph para = new Paragraph(doc);

section.Body.AppendChild(para);

builder.MoveTo(para);

builder.Writeln("New Tex");

doc.Save(MyDir + "out.docx");