CleanupOptions Class

Allows to specify options for document cleaning.

ExpandedInheritance Hierarchy

SystemObject
  Aspose.WordsCleanupOptions

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

ExpandedSyntax

public class CleanupOptions

The CleanupOptions type exposes the following members.

ExpandedConstructors

  NameDescription
Public methodCleanupOptions
Initializes a new instance of the CleanupOptions class

ExpandedProperties

  NameDescription
Public propertyCode exampleDuplicateStyle
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.

ExpandedMethods

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

ExpandedExamples

Shows how to remove all unused custom styles from a document.
Document doc = new 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 eight styles.
// A custom style is marked as "used" while there is any text within the document
// formatted in that style. This means that the 4 styles we added are currently unused.
Assert.AreEqual(8, doc.Styles.Count);

// Apply a custom character style, and then a custom list style. Doing so will mark them as "used".
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Font.Style = doc.Styles["MyParagraphStyle1"];
builder.Writeln("Hello world!");

Aspose.Words.Lists.List list = doc.Lists.Add(doc.Styles["MyListStyle1"]);
builder.ListFormat.List = list;
builder.Writeln("Item 1");
builder.Writeln("Item 2");

// Now, there is one unused character style and one unused list style.
// 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;

doc.Cleanup(cleanupOptions);

Assert.AreEqual(6, doc.Styles.Count);

// Removing every node that a custom style is applied to marks it as "unused" again. 
// Rerun the Cleanup method to remove them.
doc.FirstSection.Body.RemoveAllChildren();
doc.Cleanup(cleanupOptions);

Assert.AreEqual(4, doc.Styles.Count);

ExpandedSee Also