Free Support Forum - aspose.com

How to remove unused style in word document

Hi,

I have to find out the unused style in the document and then remove them before I output the document to the user.

sample code :

foreach (Aspose.Words.Style style in doc.Styles)
{
if (!style.BuiltIn)
{
//ToDo: Identify if style is not used and remove it
}
}

Just wondering why there is no style.Remove() method?

Amit Suri

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. You are right, currently there is no way to remove styles from the document. Your request has been linked to the appropriate issue. You will be notified as soon as this feature is available.

Best regards.

The issues you have found earlier (filed as WORDSNET-3291) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

Hi,

can you tell me how it is resolved ? I cannot find a remove method in Styles.

Kind regards,

Guido

Hi,

i cannot find any remove methodin styles. How it is solved now in 13.6 ?

Kind regards,

Guido

Hi Guido,


Thanks for your inquiry. The RemoveUnusedResources method was added to Document class to remove any unused styles and lists from the document. Please try run the following code:

Document doc = new
Document();

doc.RemoveUnusedResources();

doc.Save("");


I hope, this helps.

Best regards,

@Amit00001

Starting from Aspose.Words 21.4, you can remove unused built-in styles from document using CleanupOptions.UnusedBuiltinStyles property. Following code snippet shows how to use this property.

Document doc = new Document("input.docx");
CleanupOptions cleanupOptions = new CleanupOptions();
cleanupOptions.UnusedBuiltinStyles = true;
doc.Cleanup(cleanupOptions);