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

Free Support Forum - aspose.com

How to insert HTML contend in a Run or Table.Cell

Hi Support,

Can we put html in a Run or a Table.Cell via object?

or do we have to write our own html parsing engine which convert to Aspose OO values

i can’t find it in the api documentation, can you point me in the right direction

example should be using objects not the documentbuilder

documentbuilder will not work with what we are doing.


This message was posted using Email2Forum by Tilal Ahmad Sana.

Hi Brandon,

Thanks for your inquiry. The Run.Text property gets or sets the text of the run. You can not insert the HTML fragment or whole HTML document into a Run node. However, you can insert html inside a table’s cell.

Unfortunately, you can not insert html using Aspose.Words public API. It leaves you with the only option i.e. using DocumentBuilder.

It would be great if you please share some detail about your scenario in which DocumentBuilder is not working.

In your case, I suggest you following solution.

  1. Load the HTML into Aspose.Words DOM
  2. Insert the HTML into table’s cell using InsertDocument

Please get the code of InsertDocument method from here:


Document htmlDoc = new Document(MyDir + "in.html", new LoadOptions(LoadFormat.Html, "", ""));
Document doc = new Document(MyDir + "in.docx");
Table table = (Table)doc.GetChild(NodeType.Table, 0, true);
InsertDocument(table.FirstRow.FirstCell.FirstParagraph, htmlDoc);
doc.Save(MyDir + "Out.docx");

Actually you can insert html using the object model.

Basically you have to load the html into a new document.

Extract the paragraphs out of the new document

Dim paragraphs = doc.GetChildNodes(NodeType.Paragraph, True)

You then import the node

Dim newNode = Me.Doc.ImportNode(n, isImportChildren:=True, importFormatMode:=ImportFormatMode.KeepSourceFormatting)

and append the nodes where ever you like.

Worked like a charm.

Hi Brandon,

Thanks for your feedback.

The InsertDocument method uses the NodeImporter to import the nodes from one document to another. The InsertDocument method imports all types of nodes from one document to another document. Your approach works fine If you want to import only Paragraphs. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.