What is the purpose of the StyleIdentifier?

Hi,

I try to replace some #PlaceholderText#´s with
StructuredDocumentTag´s. For that I also need to copy the Style.
Everything works fine except some Exception with few .odt Documents.

When I try to set the StyleIdentifier I get the Exception mentioned above.

Code:

destinationFont.StyleIdentifier = sourceFont.StyleIdentifier;

Exception:
System.ArgumentException: Cannot return user defined styles by style identifier.

What is the purpose of the StyleIdentifier ?

Regards

Hi Max,

Thanks for your inquiry.

There are a lot of styles listed in StyleIdentifier enum; however, these all styles are not required to be embedded in the document. MS Word creates these styles when it is necessary. The main purpose of StyleIdentifier is language independence i.e. the names of built-in styles in MS Word are localized for different languages and using a style identifier you can find the correct style regardless of the document language.

Regarding the exception, most likely it occurs because you document does not contain a specific style. You can use code like the following to check whether a style exists:

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

Best Regards,