FontStyleName Property

Gets or sets the name of the character style applied to this formatting.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public string StyleName { get; set; }

Property Value

Type: String
Examples
Shows how to use style name or identifier to find text formatted with a specific character style and apply different character style.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert text with two styles that will be replaced by another style
builder.Font.StyleIdentifier = StyleIdentifier.Emphasis;
builder.Writeln("Text originally in \"Emphasis\" style");
builder.Font.StyleIdentifier = StyleIdentifier.IntenseEmphasis;
builder.Writeln("Text originally in \"Intense Emphasis\" style");

// Loop through every run node
foreach (Run run in doc.GetChildNodes(NodeType.Run, true).OfType<Run>())
{
    // If the run's text is of the "Emphasis" style, referenced by name, change the style to "Strong"
    if (run.Font.StyleName.Equals("Emphasis"))
        run.Font.StyleName = "Strong";

    // If the run's text style is "Intense Emphasis", change it to "Strong" also, but this time reference using a StyleIdentifier
    if (run.Font.StyleIdentifier.Equals(StyleIdentifier.IntenseEmphasis))
        run.Font.StyleIdentifier = StyleIdentifier.Strong;
}

doc.Save(ArtifactsDir + "Font.ChangeStyle.docx");
See Also