Remove
Contents
[
Hide
]Style.Remove method
Removes the specified style from the document.
public void Remove()
Remarks
Style removal has following effects on the document model:
- All references to the style are removed from corresponding paragraphs, runs and tables.
- If base style is removed its formatting is moved to child styles.
- If style to be deleted has a linked style, then both of these are deleted.
Examples
Shows how to create and apply a custom style.
Document doc = new Document();
Style style = doc.Styles.Add(StyleType.Paragraph, "MyStyle");
style.Font.Name = "Times New Roman";
style.Font.Size = 16;
style.Font.Color = Color.Navy;
// Automatically redefine style.
style.AutomaticallyUpdate = true;
DocumentBuilder builder = new DocumentBuilder(doc);
// Apply one of the styles from the document to the paragraph that the document builder is creating.
builder.ParagraphFormat.Style = doc.Styles["MyStyle"];
builder.Writeln("Hello world!");
Style firstParagraphStyle = doc.FirstSection.Body.FirstParagraph.ParagraphFormat.Style;
Assert.That(firstParagraphStyle, Is.EqualTo(style));
// Remove our custom style from the document's styles collection.
doc.Styles["MyStyle"].Remove();
firstParagraphStyle = doc.FirstSection.Body.FirstParagraph.ParagraphFormat.Style;
// Any text that used a removed style reverts to the default formatting.
Assert.That(doc.Styles.Any(s => s.Name == "MyStyle"), Is.False);
Assert.That(firstParagraphStyle.Font.Name, Is.EqualTo("Times New Roman"));
Assert.That(firstParagraphStyle.Font.Size, Is.EqualTo(12.0d));
Assert.That(firstParagraphStyle.Font.Color.ToArgb(), Is.EqualTo(Color.Empty.ToArgb()));
See Also
- class Style
- namespace Aspose.Words
- assembly Aspose.Words