Add Simple HTML to Word document Cell

Hi have a rich html editor in my app that gives users ability to do bold, underline, bullets etc - so simple html.

I need to be able to render the format (lists etc) into a word doc when exporting. Is there anyway to convert the html to rtf and insert it into a table or paragraph ?

Or alternatively is there something i can do to convert to RTF and then add that to the Table Cell or Paragraph.

Thanks

@dan-12 You do not need to convert HTML to RTF to insert formatted content into a document. You can simply use DocumentBuilder.InsertHtml method to achieve this. For example you can put a bookmark into the cell where HTML content should be inserted, then you can easily move DocumentBuilder cursor into the cell and then insert HTML:

Document doc = new Document(@"C:\Temp\in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);

builder.MoveToBookmark("html");
builder.InsertHtml("<b>Bold Text </b><i>Italic Text</i>");

doc.Save(@"C:\Temp\out.docx");

Works great! thank you!

1 Like