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

Free Support Forum - aspose.com

Support for class attribute in InsertHtml method?

It would be very useful for me to be able to insert HTML fragments and have the css class attribute interpreted as a named Word style.

Is this possible?

Thank you for your interest in Aspose.Words. Unfortunately you can’t do this using Aspose.Words. There is an issue in our defect database:
Issue #3991 - Add overload for InsertHtml method
Add new overload for InsertHtml method that will take 2 parameters.
InsertHtml(string html, MapStyles styles)
html is html string
styles is a key-value map with the key being the HTML tag name (even optionally tagName.className combination) and the value is a Word style name.
Best regards.

Hi Alexey,
It is a similar request.
To me having something like
create a paragraph and apply the named word style “somestyle” to it would be slightly more intuitive than the suggested styles map parameter though. But that’s just my opinion!

Actually one other thing that would have been useful for me is to be able to include an ID attribute
and later be able to find that node in the document tree by id.
If there was a NodeInserted event that passed in it’s event arguments a reference to the inserted node and the associated HTML fragment for that node it would make things much more extensible as I could have done both of my requirements using this.

Hi Martin,
Thanks for your request. I will consult with our developers and provide you more information.
Best regards.

While I see the usefulness of this feature, I don’t think we can provide a solution for this particular request quickly because we have quite a long backlog of things to do in HTML and CSS.
To comment some of the ideas you touched:

  1. Id for a node does not exist in Aspose.Words because its core is designed to handle MS Word documents and there is no id in those. The idea of adding ids to nodes needs to be looked at.
  2. Document already has events for node insertion and removal. They will be fired when InsertHtml is executed. Although because there are no node ids you might find it hard to detect the nodes you want.
  3. If you HTML is simple enough you can try another approach. You can get HtmlAgilityPack to parse your HTML into a node tree and then walk that tree and create proper Aspose.Words document the way you want it. Essentially build you mini HTML import.

Hi Roman,

I realise from reading other posts that there is a backlog of css requests but this would at least allow people to more easily “roll their own” solutions for missing native functionality rather than waiting a couple of years (and counting) for you to implement it yourselves.

The issues you have found earlier (filed as WORDSNET-1432) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.