CompareOptions Class

Allows to choose advanced options for document comparison operation.

ExpandedInheritance Hierarchy


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


public class CompareOptions

The CompareOptions type exposes the following members.


Public methodCompareOptions
Initializes a new instance of the CompareOptions class


Public propertyCode exampleGranularity
Specifies whether changes are tracked by character or by word. Default value is WordLevel.
Public propertyCode exampleIgnoreCaseChanges
True indicates that documents comparison is case insensitive. By default comparison is case sensitive.
Public propertyCode exampleIgnoreComments
Specifies whether to compare differences in comments. By default comments are not ignored.
Public propertyIgnoreDmlUniqueId
Specifies whether to ignore difference in DrawingML unique Id. Default value is false.
Public propertyCode exampleIgnoreFields
Specifies whether to compare differences in fields. By default fields are not ignored.
Public propertyCode exampleIgnoreFootnotes
Specifies whether to compare differences in footnotes and endnotes. By default footnotes are not ignored.
Public propertyCode exampleIgnoreFormatting
True indicates that formatting is ignored. By default document formatting is not ignored.
Public propertyCode exampleIgnoreHeadersAndFooters
True indicates that headers and footers content is ignored. By default headers and footers are not ignored.
Public propertyCode exampleIgnoreTables
Specifies whether to compare the differences in data contained in tables. By default tables are not ignored.
Public propertyCode exampleIgnoreTextboxes
Specifies whether to compare differences in the data contained within text boxes. By default textboxes are not ignored.
Public propertyCode exampleTarget
Specifies which document shall be used as a target during comparison.


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


Shows how to filter specific types of document elements when making a comparison.
// Create the original document, and populate it with various kinds of elements.
Document docOriginal = new Document();
DocumentBuilder builder = new DocumentBuilder(docOriginal);

// Paragraph text referenced with an endnote:
builder.Writeln("Hello world! This is the first paragraph.");
builder.InsertFootnote(FootnoteType.Endnote, "Original endnote text.");

// Table:
builder.Write("Original cell 1 text");
builder.Write("Original cell 2 text");

// Textbox:
Shape textBox = builder.InsertShape(ShapeType.TextBox, 150, 20);
builder.Write("Original textbox contents");

// DATE field:
builder.InsertField(" DATE ");

// Comment:
Comment newComment = new Comment(docOriginal, "John Doe", "J.D.", DateTime.Now);
newComment.SetText("Original comment.");

// Header:
builder.Writeln("Original header contents.");

// Create a clone of our document, and perform a quick edit on each of the cloned document's elements.
Document docEdited = (Document)docOriginal.Clone(true);
Paragraph firstParagraph = docEdited.FirstSection.Body.FirstParagraph;

firstParagraph.Runs[0].Text = "hello world! this is the first paragraph, after editing.";
firstParagraph.ParagraphFormat.Style = docEdited.Styles[StyleIdentifier.Heading1];
((Footnote)docEdited.GetChild(NodeType.Footnote, 0, true)).FirstParagraph.Runs[1].Text = "Edited endnote text.";
((Table)docEdited.GetChild(NodeType.Table, 0, true)).FirstRow.Cells[1].FirstParagraph.Runs[0].Text = "Edited Cell 2 contents";
((Shape)docEdited.GetChild(NodeType.Shape, 0, true)).FirstParagraph.Runs[0].Text = "Edited textbox contents";
((FieldDate)docEdited.Range.Fields[0]).UseLunarCalendar = true; 
((Comment)docEdited.GetChild(NodeType.Comment, 0, true)).FirstParagraph.Runs[0].Text = "Edited comment.";
docEdited.FirstSection.HeadersFooters[HeaderFooterType.HeaderPrimary].FirstParagraph.Runs[0].Text =
    "Edited header contents.";

// Comparing documents creates a revision for every edit in the edited document.
// A CompareOptions object has a series of flags that can suppress revisions
// on each respective type of element, effectively ignoring their change.
CompareOptions compareOptions = new CompareOptions();
compareOptions.IgnoreFormatting = false;
compareOptions.IgnoreCaseChanges = false;
compareOptions.IgnoreComments = false;
compareOptions.IgnoreTables = false;
compareOptions.IgnoreFields = false;
compareOptions.IgnoreFootnotes = false;
compareOptions.IgnoreTextboxes = false;
compareOptions.IgnoreHeadersAndFooters = false;
compareOptions.Target = ComparisonTargetType.New;

docOriginal.Compare(docEdited, "John Doe", DateTime.Now, compareOptions);
docOriginal.Save(ArtifactsDir + "Document.CompareOptions.docx");

ExpandedSee Also