Free Support Forum - aspose.com

Replacing one style wtih another in a document

Is there example code available that shows how to replace a style in a document with another style?

For example, if I have a document that uses StyleA in 10 places, I want to change all of those places to use StyleB.

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

Thank you for your inquiry.

You can select all descendant nodes of the same type with this Dcoument.GetChildNodes method:

http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/aspose.words.compositenode.getchildnodes_overload_1.html

Also you can select all the nodes satisfying some common criteria with Document.SelectNodes method:

http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/aspose.words.compositenode.selectnodes.html

I’m not sure style criterion is supported so it’s better to use the first one.

After you have selected the nodes of class Paragraph or Run depending on the style type you can change that style to some another in the simple foreach loop.

Regards,