CompareOptions Class

Allows to choose advanced options for document comparison operation.
Inheritance Hierarchy

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.2
public class CompareOptions

The CompareOptions type exposes the following members.

Public methodCompareOptions
Initializes a new instance of the CompareOptions class
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 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.)
Protected methodFinalize (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Protected methodMemberwiseClone (Inherited from Object.)
Public methodToString (Inherited from Object.)
Shows how to specify which document shall be used as a target during comparison.
// Create our original document
Document docOriginal = new Document();
DocumentBuilder builder = new DocumentBuilder(docOriginal);

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

// Insert a table
builder.Write("Original cell 1 text");
builder.Write("Original cell 2 text");

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

// Insert a DATE field
builder.InsertField(" DATE ");

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

// Insert a header
builder.Writeln("Original header contents.");

// Create a clone of our document, which we will edit and later compare to the original
Document docEdited = (Document)docOriginal.Clone(true);
Paragraph firstParagraph = docEdited.FirstSection.Body.FirstParagraph;

// Change the formatting of the first paragraph, change casing of original characters and add text
firstParagraph.Runs[0].Text = "hello world! this is the first paragraph, after editing.";
firstParagraph.ParagraphFormat.Style = docEdited.Styles[StyleIdentifier.Heading1];

// Edit the footnote
Footnote footnote = (Footnote)docEdited.GetChild(NodeType.Footnote, 0, true);
footnote.FirstParagraph.Runs[1].Text = "Edited endnote text.";

// Edit the table
Table table = (Table)docEdited.GetChild(NodeType.Table, 0, true);
table.FirstRow.Cells[1].FirstParagraph.Runs[0].Text = "Edited Cell 2 contents";

// Edit the textbox
textBox = (Shape)docEdited.GetChild(NodeType.Shape, 0, true);
textBox.FirstParagraph.Runs[0].Text = "Edited textbox contents";

// Edit the DATE field
FieldDate fieldDate = (FieldDate)docEdited.Range.Fields[0];
fieldDate.UseLunarCalendar = true;

// Edit the comment
Comment comment = (Comment)docEdited.GetChild(NodeType.Comment, 0, true);
comment.FirstParagraph.Runs[0].Text = "Edited comment.";

// Edit the header
docEdited.FirstSection.HeadersFooters[HeaderFooterType.HeaderPrimary].FirstParagraph.Runs[0].Text =
    "Edited header contents.";

// When we compare documents, the differences of the latter document from the former show up as revisions to the former
// Each edit that we've made above will have its own revision, after we run the Compare method
// We can compare with a CompareOptions object, which can suppress changes done to certain types of objects within the original document
// from registering as revisions after the comparison by setting some of these members to "true"
CompareOptions compareOptions = new CompareOptions
    IgnoreFormatting = false,
    IgnoreCaseChanges = false,
    IgnoreComments = false,
    IgnoreTables = false,
    IgnoreFields = false,
    IgnoreFootnotes = false,
    IgnoreTextboxes = false,
    IgnoreHeadersAndFooters = false,
    Target = ComparisonTargetType.New

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