CleanupOptions Class

Allows to specify options for document cleaning.

Inheritance Hierarchy


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


public class CleanupOptions

The CleanupOptions type exposes the following members.


Public methodCleanupOptions
Initializes a new instance of the CleanupOptions class


Public propertyDuplicateStyle
Gets/sets a flag indicating whether duplicate styles should be removed from document. Default value is false.
Public propertyCode exampleUnusedLists
Specifies whether unused list and list definitions should be removed from document. Default value is true.
Public propertyCode exampleUnusedStyles
Specifies whether unused styles should be removed from document. Default value is true.


Public methodEquals (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodToString (Inherited from Object.)


Shows how to remove all unused styles and lists from a document.
Document doc = new Document();

// Insert some styles into a blank document
doc.Styles.Add(StyleType.List, "MyListStyle1");
doc.Styles.Add(StyleType.List, "MyListStyle2");
doc.Styles.Add(StyleType.Character, "MyParagraphStyle1");
doc.Styles.Add(StyleType.Character, "MyParagraphStyle2");

// Combined with the built in styles, the document now has 8 styles in total,
// but all 4 of the ones we added count as unused
Assert.AreEqual(8, doc.Styles.Count);

// A character style counts as used when the document contains text in that style
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Font.Style = doc.Styles["MyParagraphStyle1"];
builder.Writeln("Hello world!");

// A list style is also "used" when there is a list that uses it
Aspose.Words.Lists.List list = doc.Lists.Add(doc.Styles["MyListStyle1"]);
builder.ListFormat.List = list;
builder.Writeln("Item 1");
builder.Writeln("Item 2");

// The Cleanup() method, when configured with a CleanupOptions object, can target unused styles and remove them
CleanupOptions cleanupOptions = new CleanupOptions();
cleanupOptions.UnusedLists = true;
cleanupOptions.UnusedStyles = true;

// We've added 4 styles and used 2 of them, so the other two will be removed when this method is called
Assert.AreEqual(6, doc.Styles.Count);

See Also