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

Free Support Forum - aspose.com

Customize Html Element Generation

Hi there,

I’m trying to use Aspose.Word to convert word to html. I want to convert all the tables in the word document to a customized div element rather than table element. I couldn’t find a way to plugin the html conversion process and replace the standard html generation. I tried to wrote my html with extending DocumentVisitor but not good. Is there a way to do this? I just want to replace the table generation, not all html generation.

Thanks in advance.

Hi there,

Thanks for your inquiry. Please use following code example to convert the table to HTML. Hope this helps you.

You may iterate over rows and cells of table, get the cell’s content and write the html according to your requirement. If you face any issue, please share your input document and expected output HTML here for our reference. We will then provide you more information about your query.

Document doc = new Aspose.Words.Document(MyDir + "input.docx");
foreach (Table table in doc.GetChildNodes(NodeType.Table, true))
    String html = table.ToString(SaveFormat.Html);

Thanks for your reply. I knew this way to obtain the html. Currently, what I did is, get the document’s sections, and then render the body, and then render the childnodes of body, and then recursively render the node and it’s childnodes. And if the node is a table, I returned my own html (div). For other nodes, return standard html string. (x.ToString(SaveFormat.Html)). This looks not good and some nodes might be missing. What I wondered was whether there is a method or callback to replace the standard html. Somethind like this:

var saveOptions = new HtmlSaveOption(SaveFormat.Html);
saveOptions.OnRendering += RenderElement…

Or there is a plugin like DoumentVisitor for html generation, like:

doc.Accept(new TableHtmlConvertor());

When doc saving, it would call either the event or plugin to get the html string. If the method returns nothing, then use standard html string, otherwise use customized one.

I had done a basic html generation by document tree nodes traversal. However, most nodes use standard one. So I asked here to check if I miss something.


Hi there,

Thanks for your inquiry.

In your case, we suggest you please use DocumentVisitor and convert the nodes to HTML. Please check the example of DocumentVisitor from following link. Hope this helps you.
How to Extract Content using DocumentVisitor