DocumentCleanup Method

Cleans unused styles and lists from the document.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.7.0


public void Cleanup()


Shows how to remove unused styles and lists from a document.
// Create a new document
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add two styles and apply them to the builder's formats, marking them as "used" 
builder.ParagraphFormat.Style = doc.Styles.Add(StyleType.Paragraph, "My Used Style");
builder.ListFormat.List = doc.Lists.Add(ListTemplate.BulletDiamonds);

// And two more styles and leave them unused by not applying them to anything
doc.Styles.Add(StyleType.Paragraph, "My Unused Style");


// The used styles are still in the document
Assert.NotNull(doc.Styles["My Used Style"]);
Assert.IsTrue(doc.Lists.Any(l => l.ListLevels[0].NumberStyle == NumberStyle.Bullet));

// The unused styles have been removed
Assert.IsNull(doc.Styles["My Unused Style"]);
Assert.IsFalse(doc.Lists.Any(l => l.ListLevels[0].NumberStyle == NumberStyle.Arabic));

See Also