Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
What is this page about?
This page outlines how to clean up unnecessary or redundant content in a Word document using Aspose.Words.
Sometimes you may need to remove unused or duplicate information to reduce the size of the output document and processing time.
While you can find and remove unused data, such as styles or lists, or duplicate information manually, it will be much more convenient to do this using features and capabilities provided by Aspose.Words.
The CleanupOptions class allows you to specify options for document cleaning. To remove duplicate styles or just unused styles or lists from the document, you can use the Cleanup method.
You can use the UnusedStyles and UnusedBuiltinStyles properties to detect and remove styles that are marked as “unused”.
You can use the UnusedLists property to detect and remove lists and list definitions that are marked as “unused”.
The following code example shows how to remove only unused styles from a document:
You can also use the DuplicateStyle property to substitute all duplicate styles with the original one and remove duplicates from a document.
The following code example shows how to remove duplicate styles from a document:
Q: How can I remove only the unused styles from a document?
A: Create a CleanupOptions instance, set UnusedStyles to true, and call document.Cleanup(options). This removes styles that are not applied anywhere in the document while leaving used styles intact.
Q: What is the difference between UnusedBuiltinStyles and UnusedStyles?
A: UnusedBuiltinStyles targets the built‑in Word styles (e.g., Normal, Heading 1) that are not used, whereas UnusedStyles applies to custom styles defined in the document. Enabling both removes all unused style definitions.
Q: Can I clean up duplicate styles in a single operation?
A: Yes. Set the DuplicateStyle property of CleanupOptions to true and invoke document.Cleanup(options). Aspose.Words will replace duplicate style definitions with a single original style and delete the duplicates.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.