Cascading Styles in Aspose.Word


I was able to emulate the behavior of CSS in Aspose.Pdf by passing around a global TextInfo object and updating it as needed. I did this with MarginInfo, BorderInfo and AlignmentType as well.

I’d like to use the DocumentBuilder class but I only see one, global Font object supported. Is there a way to modify the font within a table or paragraph without changing the global Font style? In other words, the Aspose.Pdf DOM supported the cascading effect quite nicely. Do you have a recommendation for the best approach with Aspose.Word?

Thanks, Natan.


Hi Natan,

Thank you for considering Aspose.

First, let me correct you. DocumentBuilder.Font is not a global object. When you move the builder cursor to a particular node, the builder “attaches” to the current formatting so if you change it, the current node formatting is changed as well. However, Font is the only exception - font attributes are copied from the node into DocumentBuilder.Font. This is similar to MS Word: if you just move a cursor to a place - you can see font attributes are updated on the toolbars, but if you change size or bold, it does not change font of the current run of text. It only affects text that will be inserted.

Therefore a good approach you can use to modify font within a paragraph or table is using GetChildNodes to select all the runs of the particular node, iterate through the collection and set font properties as required. For example, for a table it could look like this:

NodeCollection runs = table.GetChildNodes(NodeType.Run, true);

foreach (Run run in runs)
// Set run.Font properties as required


We don’t have cascading styles in Aspose.Word since we model an MS Word document pretty closely. If we try to introduce cascading styles, it could be a bit tricky for us to provide MS Word - like features and behaviour and will probably confuse many users. So adding cascading styles to Aspose.Word is a question open for discussion.