GemBox Support Forum

Replacing text with bulleted list

Hi, I have a document that contains a collection of text placeholders. I’d like to replace these placeholders with various elements at runtime such a bulleted list, but I’d like the list to be in the same style format as the placeholder. e.g. If the text <> is in a certain font, size, colour then I’d like the list to be in the same style when it replaces the placeholder. I’m able to replace the placeholder with a list but seem to be having difficulty ensuring the style is preserved. Many Thanks.


You could retrieve the format of the placeholder text and use it on your new elements, but I believe the easiest way would be to use HTML content and inherit the placeholder formatting when importing that content.

For example, try this:

var document = DocumentModel.Load("input.docx");
var placeholder = document.Content.Find("PLACEHOLDER TEXT").First();

var html = "<ul><li>Sample 1</li><li>Sample 2</li><li>Sample 3</li></ul>";
var htmlOptions = new HtmlLoadOptions() { InheritCharacterFormat = true, InheritParagraphFormat = true };

placeholder.LoadText(html, htmlOptions);


I hope this helps.


Thanks Mario, the solution worked perfectly