We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Compare Styles of Word document

Hi,

Is there any method/ way which compares the two styles of Word document and says if the two styles are same or different. A traditional way which I encountered was to compare all the attributes between the two Style objects. But the style object inturn has many attributes and hence the comparison becomes tedious process.

Thanks in advance.

Hello!

Thank you for your interest in Aspose products.

That’s a very specific task and it can not be solved in one method call. Do you mean Aspose.Words.Style class? When do you have to deeply compare two Style objects? We can make it comparable, of course after internal discussion, but I don’t see any intelligible reason for that. Please explain what the task you are solving needs this so I could make any other suggestions.

Regards,

Hi,

My requirement is I need to compare the styles of two Word documents and check if the style in one document is present in other. I am able to get the styles of Word document by loading the document and checking for the styles property. There are chances wherein the styles of the two document may be diferrent but have the same name or the styles may be same but have a different name. I should be able to compare the two styles irrespective of their name and identify whether they are identical. How do I achieve this.

Thank you for explanation. I have logged this improvement as # 3827 in our database. We’ll investigate how it’s better to provide this functionality and implement it in one of the future releases. If you want a quick solution please attach two sample documents you need to process this way so we could help with workaround. Really we can advise something like what you call “tedious process”, nothing new at this point.

Have a nice day,

Let's talk the API and the commpare logic through, we might will look at implementing it.

How would you want to compare the styles?

A style has a few properties of its own (owner document, style name, style id, style type, id of the based on style, id of the next style and so on) as well as one or more collections of formatting attributes (font and paragraph).

I don't think that simple approach

style.IsSameAs(otherStyle);

will be acceptable. By looking at this code I would expect that it compares all properties of a style, but I doubt comparing all properties of a style will ever make sense.

A style can have same formatting, but different id in different documents. A style can have same formatting, but be based on different styles. There are many scenarios to consider.

How do you want the compare operation to take into account based on styles? These are the styles that the style "inherits" from.

If we can figure out how it should be in the API it will not be a problem to do it.