Search code examples
c#ms-worddocxxceed

How to replace a paragraph with formatting text using xceed docx?


I want to replace some text in a docx file, and i'm using XCeed Docx lib, i want to ask if there is any way to replace the text with a new formatted text? For exemple i have the %value% (normal text) and i want to replace it with bold text to replace only the text i use the function document.ReplaceText(%value%, "Bold text"). Remark not all the replace text need to be bold and i do not know if the next is bold or not, i need the bold text only in some situations.


Solution

  • try this:

    Formatting formatting = new Formatting();
    formatting.Bold = true;
    doc.ReplaceText("%value%", "Bold Text", false, System.Text.RegularExpressions.RegexOptions.None, formatting);