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

Free Support Forum - aspose.com

Cannot find a style with this style identifier - StyleIdentifier.SubtleEmphasis


I’m getting an exception saying “Cannot find a style with this style identifier.” when attempting to set this style in a document I’m creating:

builder.CurrentParagraph.ParagraphFormat.StyleIdentifier = StyleIdentifier.SubtleEmphasis;

Can you please comment on this.

Also, how can I check if a style exists or not?



Thanks for your request. This occurs because you document does not contain such style. You can use code like the following to check whether style exists:

// Get style.
Style style = doc.Styles[StyleIdentifier.SubtleEmphasis];
// Check whether style exists
if (style != null)
    // Do something

Hope this helps.
Best regards.

Thanks Alexey,

I am curious as to why that style identifier is enumerated if the style does not exist in the document? If I am creating a new document, is there a way to load this style from somewhere, or is my only choice to create this style.



Thanks for your request. There are a lot of styles listed in StyleIdentified enum:
They all are not required to be embedded in document. MS Word creates them when it is necessary. The main purpose of StyleIdentifier is language independence (see documentation).
Best regards.