java.lang.Object
com.aspose.words.CompareOptions
public class CompareOptions
- extends java.lang.Object
Allows to choose advanced options for document comparison operation.
Example:
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.startTable();
builder.insertCell();
builder.write("Original cell 1 text");
builder.insertCell();
builder.write("Original cell 2 text");
builder.endTable();
// Insert a textbox
Shape textBox = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 20.0);
builder.moveTo(textBox.getFirstParagraph());
builder.write("Original textbox contents");
// Insert a DATE field
builder.moveTo(docOriginal.getFirstSection().getBody().appendParagraph(""));
builder.insertField(" DATE ");
// Insert a comment
Comment newComment = new Comment(docOriginal, "John Doe", "J.D.", new Date());
newComment.setText("Original comment.");
builder.getCurrentParagraph().appendChild(newComment);
// Insert a header
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
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.deepClone(true);
Paragraph firstParagraph = docEdited.getFirstSection().getBody().getFirstParagraph();
// Change the formatting of the first paragraph, change casing of original characters and add text
firstParagraph.getRuns().get(0).setText("hello world! this is the first paragraph, after editing.");
firstParagraph.getParagraphFormat().setStyle(docEdited.getStyles().getByStyleIdentifier(StyleIdentifier.HEADING_1));
// Edit the footnote
Footnote footnote = (Footnote) docEdited.getChild(NodeType.FOOTNOTE, 0, true);
footnote.getFirstParagraph().getRuns().get(1).setText("Edited endnote text.");
// Edit the table
Table table = (Table) docEdited.getChild(NodeType.TABLE, 0, true);
table.getFirstRow().getCells().get(1).getFirstParagraph().getRuns().get(0).setText("Edited Cell 2 contents");
// Edit the textbox
textBox = (Shape) docEdited.getChild(NodeType.SHAPE, 0, true);
textBox.getFirstParagraph().getRuns().get(0).setText("Edited textbox contents");
// Edit the DATE field
FieldDate fieldDate = (FieldDate) docEdited.getRange().getFields().get(0);
fieldDate.setUseLunarCalendar(true);
// Edit the comment
Comment comment = (Comment) docEdited.getChild(NodeType.COMMENT, 0, true);
comment.getFirstParagraph().getRuns().get(0).setText("Edited comment.");
// Edit the header
docEdited.getFirstSection().getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY).getFirstParagraph().getRuns().get(0).setText("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();
compareOptions.setIgnoreFormatting(false);
compareOptions.setIgnoreCaseChanges(false);
compareOptions.setIgnoreComments(false);
compareOptions.setIgnoreTables(false);
compareOptions.setIgnoreFields(false);
compareOptions.setIgnoreFootnotes(false);
compareOptions.setIgnoreTextboxes(false);
compareOptions.setIgnoreHeadersAndFooters(false);
compareOptions.setTarget(ComparisonTargetType.NEW);
docOriginal.compare(docEdited, "John Doe", new Date(), compareOptions);
docOriginal.save(getArtifactsDir() + "Document.CompareOptions.docx");
CompareOptions
public CompareOptions()
-
Property Getters/Setters Detail |
getGranularity/setGranularity | |
public int getGranularity() / public void setGranularity(int value)
|
-
Specifies whether changes are tracked by character or by word.
Default value is Granularity.WORD_LEVEL.
The value of the property is Granularity integer constant.
Example:
Shows to specify comparison granularity.
Document docA = new Document();
DocumentBuilder builderA = new DocumentBuilder(docA);
builderA.writeln("Alpha Lorem ipsum dolor sit amet, consectetur adipiscing elit");
Document docB = new Document();
DocumentBuilder builderB = new DocumentBuilder(docB);
builderB.writeln("Lorems ipsum dolor sit amet consectetur - \"adipiscing\" elit");
// Specify whether changes are tracked by character ('Granularity.CharLevel') or by word ('Granularity.WordLevel')
CompareOptions compareOptions = new CompareOptions();
compareOptions.setGranularity(granularity);
docA.compare(docB, "author", new Date(), compareOptions);
// Revision groups contain all of our text changes
RevisionGroupCollection groups = docA.getRevisions().getGroups();
Assert.assertEquals(5, groups.getCount());
getIgnoreCaseChanges/setIgnoreCaseChanges | |
public boolean getIgnoreCaseChanges() / public void setIgnoreCaseChanges(boolean value)
|
-
True indicates that documents comparison is case insensitive.
By default comparison is case sensitive.
Example:
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.startTable();
builder.insertCell();
builder.write("Original cell 1 text");
builder.insertCell();
builder.write("Original cell 2 text");
builder.endTable();
// Insert a textbox
Shape textBox = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 20.0);
builder.moveTo(textBox.getFirstParagraph());
builder.write("Original textbox contents");
// Insert a DATE field
builder.moveTo(docOriginal.getFirstSection().getBody().appendParagraph(""));
builder.insertField(" DATE ");
// Insert a comment
Comment newComment = new Comment(docOriginal, "John Doe", "J.D.", new Date());
newComment.setText("Original comment.");
builder.getCurrentParagraph().appendChild(newComment);
// Insert a header
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
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.deepClone(true);
Paragraph firstParagraph = docEdited.getFirstSection().getBody().getFirstParagraph();
// Change the formatting of the first paragraph, change casing of original characters and add text
firstParagraph.getRuns().get(0).setText("hello world! this is the first paragraph, after editing.");
firstParagraph.getParagraphFormat().setStyle(docEdited.getStyles().getByStyleIdentifier(StyleIdentifier.HEADING_1));
// Edit the footnote
Footnote footnote = (Footnote) docEdited.getChild(NodeType.FOOTNOTE, 0, true);
footnote.getFirstParagraph().getRuns().get(1).setText("Edited endnote text.");
// Edit the table
Table table = (Table) docEdited.getChild(NodeType.TABLE, 0, true);
table.getFirstRow().getCells().get(1).getFirstParagraph().getRuns().get(0).setText("Edited Cell 2 contents");
// Edit the textbox
textBox = (Shape) docEdited.getChild(NodeType.SHAPE, 0, true);
textBox.getFirstParagraph().getRuns().get(0).setText("Edited textbox contents");
// Edit the DATE field
FieldDate fieldDate = (FieldDate) docEdited.getRange().getFields().get(0);
fieldDate.setUseLunarCalendar(true);
// Edit the comment
Comment comment = (Comment) docEdited.getChild(NodeType.COMMENT, 0, true);
comment.getFirstParagraph().getRuns().get(0).setText("Edited comment.");
// Edit the header
docEdited.getFirstSection().getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY).getFirstParagraph().getRuns().get(0).setText("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();
compareOptions.setIgnoreFormatting(false);
compareOptions.setIgnoreCaseChanges(false);
compareOptions.setIgnoreComments(false);
compareOptions.setIgnoreTables(false);
compareOptions.setIgnoreFields(false);
compareOptions.setIgnoreFootnotes(false);
compareOptions.setIgnoreTextboxes(false);
compareOptions.setIgnoreHeadersAndFooters(false);
compareOptions.setTarget(ComparisonTargetType.NEW);
docOriginal.compare(docEdited, "John Doe", new Date(), compareOptions);
docOriginal.save(getArtifactsDir() + "Document.CompareOptions.docx");
getIgnoreComments/setIgnoreComments | |
public boolean getIgnoreComments() / public void setIgnoreComments(boolean value)
|
-
Specifies whether to compare differences in comments.
By default comments are not ignored.
Example:
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.startTable();
builder.insertCell();
builder.write("Original cell 1 text");
builder.insertCell();
builder.write("Original cell 2 text");
builder.endTable();
// Insert a textbox
Shape textBox = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 20.0);
builder.moveTo(textBox.getFirstParagraph());
builder.write("Original textbox contents");
// Insert a DATE field
builder.moveTo(docOriginal.getFirstSection().getBody().appendParagraph(""));
builder.insertField(" DATE ");
// Insert a comment
Comment newComment = new Comment(docOriginal, "John Doe", "J.D.", new Date());
newComment.setText("Original comment.");
builder.getCurrentParagraph().appendChild(newComment);
// Insert a header
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
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.deepClone(true);
Paragraph firstParagraph = docEdited.getFirstSection().getBody().getFirstParagraph();
// Change the formatting of the first paragraph, change casing of original characters and add text
firstParagraph.getRuns().get(0).setText("hello world! this is the first paragraph, after editing.");
firstParagraph.getParagraphFormat().setStyle(docEdited.getStyles().getByStyleIdentifier(StyleIdentifier.HEADING_1));
// Edit the footnote
Footnote footnote = (Footnote) docEdited.getChild(NodeType.FOOTNOTE, 0, true);
footnote.getFirstParagraph().getRuns().get(1).setText("Edited endnote text.");
// Edit the table
Table table = (Table) docEdited.getChild(NodeType.TABLE, 0, true);
table.getFirstRow().getCells().get(1).getFirstParagraph().getRuns().get(0).setText("Edited Cell 2 contents");
// Edit the textbox
textBox = (Shape) docEdited.getChild(NodeType.SHAPE, 0, true);
textBox.getFirstParagraph().getRuns().get(0).setText("Edited textbox contents");
// Edit the DATE field
FieldDate fieldDate = (FieldDate) docEdited.getRange().getFields().get(0);
fieldDate.setUseLunarCalendar(true);
// Edit the comment
Comment comment = (Comment) docEdited.getChild(NodeType.COMMENT, 0, true);
comment.getFirstParagraph().getRuns().get(0).setText("Edited comment.");
// Edit the header
docEdited.getFirstSection().getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY).getFirstParagraph().getRuns().get(0).setText("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();
compareOptions.setIgnoreFormatting(false);
compareOptions.setIgnoreCaseChanges(false);
compareOptions.setIgnoreComments(false);
compareOptions.setIgnoreTables(false);
compareOptions.setIgnoreFields(false);
compareOptions.setIgnoreFootnotes(false);
compareOptions.setIgnoreTextboxes(false);
compareOptions.setIgnoreHeadersAndFooters(false);
compareOptions.setTarget(ComparisonTargetType.NEW);
docOriginal.compare(docEdited, "John Doe", new Date(), compareOptions);
docOriginal.save(getArtifactsDir() + "Document.CompareOptions.docx");
getIgnoreFields/setIgnoreFields | |
public boolean getIgnoreFields() / public void setIgnoreFields(boolean value)
|
-
Specifies whether to compare differences in fields.
By default fields are not ignored.
Example:
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.startTable();
builder.insertCell();
builder.write("Original cell 1 text");
builder.insertCell();
builder.write("Original cell 2 text");
builder.endTable();
// Insert a textbox
Shape textBox = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 20.0);
builder.moveTo(textBox.getFirstParagraph());
builder.write("Original textbox contents");
// Insert a DATE field
builder.moveTo(docOriginal.getFirstSection().getBody().appendParagraph(""));
builder.insertField(" DATE ");
// Insert a comment
Comment newComment = new Comment(docOriginal, "John Doe", "J.D.", new Date());
newComment.setText("Original comment.");
builder.getCurrentParagraph().appendChild(newComment);
// Insert a header
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
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.deepClone(true);
Paragraph firstParagraph = docEdited.getFirstSection().getBody().getFirstParagraph();
// Change the formatting of the first paragraph, change casing of original characters and add text
firstParagraph.getRuns().get(0).setText("hello world! this is the first paragraph, after editing.");
firstParagraph.getParagraphFormat().setStyle(docEdited.getStyles().getByStyleIdentifier(StyleIdentifier.HEADING_1));
// Edit the footnote
Footnote footnote = (Footnote) docEdited.getChild(NodeType.FOOTNOTE, 0, true);
footnote.getFirstParagraph().getRuns().get(1).setText("Edited endnote text.");
// Edit the table
Table table = (Table) docEdited.getChild(NodeType.TABLE, 0, true);
table.getFirstRow().getCells().get(1).getFirstParagraph().getRuns().get(0).setText("Edited Cell 2 contents");
// Edit the textbox
textBox = (Shape) docEdited.getChild(NodeType.SHAPE, 0, true);
textBox.getFirstParagraph().getRuns().get(0).setText("Edited textbox contents");
// Edit the DATE field
FieldDate fieldDate = (FieldDate) docEdited.getRange().getFields().get(0);
fieldDate.setUseLunarCalendar(true);
// Edit the comment
Comment comment = (Comment) docEdited.getChild(NodeType.COMMENT, 0, true);
comment.getFirstParagraph().getRuns().get(0).setText("Edited comment.");
// Edit the header
docEdited.getFirstSection().getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY).getFirstParagraph().getRuns().get(0).setText("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();
compareOptions.setIgnoreFormatting(false);
compareOptions.setIgnoreCaseChanges(false);
compareOptions.setIgnoreComments(false);
compareOptions.setIgnoreTables(false);
compareOptions.setIgnoreFields(false);
compareOptions.setIgnoreFootnotes(false);
compareOptions.setIgnoreTextboxes(false);
compareOptions.setIgnoreHeadersAndFooters(false);
compareOptions.setTarget(ComparisonTargetType.NEW);
docOriginal.compare(docEdited, "John Doe", new Date(), compareOptions);
docOriginal.save(getArtifactsDir() + "Document.CompareOptions.docx");
getIgnoreFootnotes/setIgnoreFootnotes | |
public boolean getIgnoreFootnotes() / public void setIgnoreFootnotes(boolean value)
|
-
Specifies whether to compare differences in footnotes and endnotes.
By default footnotes are not ignored.
Example:
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.startTable();
builder.insertCell();
builder.write("Original cell 1 text");
builder.insertCell();
builder.write("Original cell 2 text");
builder.endTable();
// Insert a textbox
Shape textBox = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 20.0);
builder.moveTo(textBox.getFirstParagraph());
builder.write("Original textbox contents");
// Insert a DATE field
builder.moveTo(docOriginal.getFirstSection().getBody().appendParagraph(""));
builder.insertField(" DATE ");
// Insert a comment
Comment newComment = new Comment(docOriginal, "John Doe", "J.D.", new Date());
newComment.setText("Original comment.");
builder.getCurrentParagraph().appendChild(newComment);
// Insert a header
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
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.deepClone(true);
Paragraph firstParagraph = docEdited.getFirstSection().getBody().getFirstParagraph();
// Change the formatting of the first paragraph, change casing of original characters and add text
firstParagraph.getRuns().get(0).setText("hello world! this is the first paragraph, after editing.");
firstParagraph.getParagraphFormat().setStyle(docEdited.getStyles().getByStyleIdentifier(StyleIdentifier.HEADING_1));
// Edit the footnote
Footnote footnote = (Footnote) docEdited.getChild(NodeType.FOOTNOTE, 0, true);
footnote.getFirstParagraph().getRuns().get(1).setText("Edited endnote text.");
// Edit the table
Table table = (Table) docEdited.getChild(NodeType.TABLE, 0, true);
table.getFirstRow().getCells().get(1).getFirstParagraph().getRuns().get(0).setText("Edited Cell 2 contents");
// Edit the textbox
textBox = (Shape) docEdited.getChild(NodeType.SHAPE, 0, true);
textBox.getFirstParagraph().getRuns().get(0).setText("Edited textbox contents");
// Edit the DATE field
FieldDate fieldDate = (FieldDate) docEdited.getRange().getFields().get(0);
fieldDate.setUseLunarCalendar(true);
// Edit the comment
Comment comment = (Comment) docEdited.getChild(NodeType.COMMENT, 0, true);
comment.getFirstParagraph().getRuns().get(0).setText("Edited comment.");
// Edit the header
docEdited.getFirstSection().getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY).getFirstParagraph().getRuns().get(0).setText("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();
compareOptions.setIgnoreFormatting(false);
compareOptions.setIgnoreCaseChanges(false);
compareOptions.setIgnoreComments(false);
compareOptions.setIgnoreTables(false);
compareOptions.setIgnoreFields(false);
compareOptions.setIgnoreFootnotes(false);
compareOptions.setIgnoreTextboxes(false);
compareOptions.setIgnoreHeadersAndFooters(false);
compareOptions.setTarget(ComparisonTargetType.NEW);
docOriginal.compare(docEdited, "John Doe", new Date(), compareOptions);
docOriginal.save(getArtifactsDir() + "Document.CompareOptions.docx");
getIgnoreFormatting/setIgnoreFormatting | |
public boolean getIgnoreFormatting() / public void setIgnoreFormatting(boolean value)
|
-
True indicates that formatting is ignored.
By default document formatting is not ignored.
Example:
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.startTable();
builder.insertCell();
builder.write("Original cell 1 text");
builder.insertCell();
builder.write("Original cell 2 text");
builder.endTable();
// Insert a textbox
Shape textBox = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 20.0);
builder.moveTo(textBox.getFirstParagraph());
builder.write("Original textbox contents");
// Insert a DATE field
builder.moveTo(docOriginal.getFirstSection().getBody().appendParagraph(""));
builder.insertField(" DATE ");
// Insert a comment
Comment newComment = new Comment(docOriginal, "John Doe", "J.D.", new Date());
newComment.setText("Original comment.");
builder.getCurrentParagraph().appendChild(newComment);
// Insert a header
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
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.deepClone(true);
Paragraph firstParagraph = docEdited.getFirstSection().getBody().getFirstParagraph();
// Change the formatting of the first paragraph, change casing of original characters and add text
firstParagraph.getRuns().get(0).setText("hello world! this is the first paragraph, after editing.");
firstParagraph.getParagraphFormat().setStyle(docEdited.getStyles().getByStyleIdentifier(StyleIdentifier.HEADING_1));
// Edit the footnote
Footnote footnote = (Footnote) docEdited.getChild(NodeType.FOOTNOTE, 0, true);
footnote.getFirstParagraph().getRuns().get(1).setText("Edited endnote text.");
// Edit the table
Table table = (Table) docEdited.getChild(NodeType.TABLE, 0, true);
table.getFirstRow().getCells().get(1).getFirstParagraph().getRuns().get(0).setText("Edited Cell 2 contents");
// Edit the textbox
textBox = (Shape) docEdited.getChild(NodeType.SHAPE, 0, true);
textBox.getFirstParagraph().getRuns().get(0).setText("Edited textbox contents");
// Edit the DATE field
FieldDate fieldDate = (FieldDate) docEdited.getRange().getFields().get(0);
fieldDate.setUseLunarCalendar(true);
// Edit the comment
Comment comment = (Comment) docEdited.getChild(NodeType.COMMENT, 0, true);
comment.getFirstParagraph().getRuns().get(0).setText("Edited comment.");
// Edit the header
docEdited.getFirstSection().getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY).getFirstParagraph().getRuns().get(0).setText("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();
compareOptions.setIgnoreFormatting(false);
compareOptions.setIgnoreCaseChanges(false);
compareOptions.setIgnoreComments(false);
compareOptions.setIgnoreTables(false);
compareOptions.setIgnoreFields(false);
compareOptions.setIgnoreFootnotes(false);
compareOptions.setIgnoreTextboxes(false);
compareOptions.setIgnoreHeadersAndFooters(false);
compareOptions.setTarget(ComparisonTargetType.NEW);
docOriginal.compare(docEdited, "John Doe", new Date(), compareOptions);
docOriginal.save(getArtifactsDir() + "Document.CompareOptions.docx");
getIgnoreHeadersAndFooters/setIgnoreHeadersAndFooters | |
public boolean getIgnoreHeadersAndFooters() / public void setIgnoreHeadersAndFooters(boolean value)
|
-
True indicates that headers and footers content is ignored.
By default headers and footers are not ignored.
Example:
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.startTable();
builder.insertCell();
builder.write("Original cell 1 text");
builder.insertCell();
builder.write("Original cell 2 text");
builder.endTable();
// Insert a textbox
Shape textBox = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 20.0);
builder.moveTo(textBox.getFirstParagraph());
builder.write("Original textbox contents");
// Insert a DATE field
builder.moveTo(docOriginal.getFirstSection().getBody().appendParagraph(""));
builder.insertField(" DATE ");
// Insert a comment
Comment newComment = new Comment(docOriginal, "John Doe", "J.D.", new Date());
newComment.setText("Original comment.");
builder.getCurrentParagraph().appendChild(newComment);
// Insert a header
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
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.deepClone(true);
Paragraph firstParagraph = docEdited.getFirstSection().getBody().getFirstParagraph();
// Change the formatting of the first paragraph, change casing of original characters and add text
firstParagraph.getRuns().get(0).setText("hello world! this is the first paragraph, after editing.");
firstParagraph.getParagraphFormat().setStyle(docEdited.getStyles().getByStyleIdentifier(StyleIdentifier.HEADING_1));
// Edit the footnote
Footnote footnote = (Footnote) docEdited.getChild(NodeType.FOOTNOTE, 0, true);
footnote.getFirstParagraph().getRuns().get(1).setText("Edited endnote text.");
// Edit the table
Table table = (Table) docEdited.getChild(NodeType.TABLE, 0, true);
table.getFirstRow().getCells().get(1).getFirstParagraph().getRuns().get(0).setText("Edited Cell 2 contents");
// Edit the textbox
textBox = (Shape) docEdited.getChild(NodeType.SHAPE, 0, true);
textBox.getFirstParagraph().getRuns().get(0).setText("Edited textbox contents");
// Edit the DATE field
FieldDate fieldDate = (FieldDate) docEdited.getRange().getFields().get(0);
fieldDate.setUseLunarCalendar(true);
// Edit the comment
Comment comment = (Comment) docEdited.getChild(NodeType.COMMENT, 0, true);
comment.getFirstParagraph().getRuns().get(0).setText("Edited comment.");
// Edit the header
docEdited.getFirstSection().getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY).getFirstParagraph().getRuns().get(0).setText("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();
compareOptions.setIgnoreFormatting(false);
compareOptions.setIgnoreCaseChanges(false);
compareOptions.setIgnoreComments(false);
compareOptions.setIgnoreTables(false);
compareOptions.setIgnoreFields(false);
compareOptions.setIgnoreFootnotes(false);
compareOptions.setIgnoreTextboxes(false);
compareOptions.setIgnoreHeadersAndFooters(false);
compareOptions.setTarget(ComparisonTargetType.NEW);
docOriginal.compare(docEdited, "John Doe", new Date(), compareOptions);
docOriginal.save(getArtifactsDir() + "Document.CompareOptions.docx");
getIgnoreTables/setIgnoreTables | |
public boolean getIgnoreTables() / public void setIgnoreTables(boolean value)
|
-
Specifies whether to compare the differences in data contained in tables.
By default tables are not ignored.
Example:
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.startTable();
builder.insertCell();
builder.write("Original cell 1 text");
builder.insertCell();
builder.write("Original cell 2 text");
builder.endTable();
// Insert a textbox
Shape textBox = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 20.0);
builder.moveTo(textBox.getFirstParagraph());
builder.write("Original textbox contents");
// Insert a DATE field
builder.moveTo(docOriginal.getFirstSection().getBody().appendParagraph(""));
builder.insertField(" DATE ");
// Insert a comment
Comment newComment = new Comment(docOriginal, "John Doe", "J.D.", new Date());
newComment.setText("Original comment.");
builder.getCurrentParagraph().appendChild(newComment);
// Insert a header
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
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.deepClone(true);
Paragraph firstParagraph = docEdited.getFirstSection().getBody().getFirstParagraph();
// Change the formatting of the first paragraph, change casing of original characters and add text
firstParagraph.getRuns().get(0).setText("hello world! this is the first paragraph, after editing.");
firstParagraph.getParagraphFormat().setStyle(docEdited.getStyles().getByStyleIdentifier(StyleIdentifier.HEADING_1));
// Edit the footnote
Footnote footnote = (Footnote) docEdited.getChild(NodeType.FOOTNOTE, 0, true);
footnote.getFirstParagraph().getRuns().get(1).setText("Edited endnote text.");
// Edit the table
Table table = (Table) docEdited.getChild(NodeType.TABLE, 0, true);
table.getFirstRow().getCells().get(1).getFirstParagraph().getRuns().get(0).setText("Edited Cell 2 contents");
// Edit the textbox
textBox = (Shape) docEdited.getChild(NodeType.SHAPE, 0, true);
textBox.getFirstParagraph().getRuns().get(0).setText("Edited textbox contents");
// Edit the DATE field
FieldDate fieldDate = (FieldDate) docEdited.getRange().getFields().get(0);
fieldDate.setUseLunarCalendar(true);
// Edit the comment
Comment comment = (Comment) docEdited.getChild(NodeType.COMMENT, 0, true);
comment.getFirstParagraph().getRuns().get(0).setText("Edited comment.");
// Edit the header
docEdited.getFirstSection().getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY).getFirstParagraph().getRuns().get(0).setText("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();
compareOptions.setIgnoreFormatting(false);
compareOptions.setIgnoreCaseChanges(false);
compareOptions.setIgnoreComments(false);
compareOptions.setIgnoreTables(false);
compareOptions.setIgnoreFields(false);
compareOptions.setIgnoreFootnotes(false);
compareOptions.setIgnoreTextboxes(false);
compareOptions.setIgnoreHeadersAndFooters(false);
compareOptions.setTarget(ComparisonTargetType.NEW);
docOriginal.compare(docEdited, "John Doe", new Date(), compareOptions);
docOriginal.save(getArtifactsDir() + "Document.CompareOptions.docx");
getIgnoreTextboxes/setIgnoreTextboxes | |
public boolean getIgnoreTextboxes() / public void setIgnoreTextboxes(boolean value)
|
-
Specifies whether to compare differences in the data contained within text boxes.
By default textboxes are not ignored.
Example:
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.startTable();
builder.insertCell();
builder.write("Original cell 1 text");
builder.insertCell();
builder.write("Original cell 2 text");
builder.endTable();
// Insert a textbox
Shape textBox = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 20.0);
builder.moveTo(textBox.getFirstParagraph());
builder.write("Original textbox contents");
// Insert a DATE field
builder.moveTo(docOriginal.getFirstSection().getBody().appendParagraph(""));
builder.insertField(" DATE ");
// Insert a comment
Comment newComment = new Comment(docOriginal, "John Doe", "J.D.", new Date());
newComment.setText("Original comment.");
builder.getCurrentParagraph().appendChild(newComment);
// Insert a header
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
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.deepClone(true);
Paragraph firstParagraph = docEdited.getFirstSection().getBody().getFirstParagraph();
// Change the formatting of the first paragraph, change casing of original characters and add text
firstParagraph.getRuns().get(0).setText("hello world! this is the first paragraph, after editing.");
firstParagraph.getParagraphFormat().setStyle(docEdited.getStyles().getByStyleIdentifier(StyleIdentifier.HEADING_1));
// Edit the footnote
Footnote footnote = (Footnote) docEdited.getChild(NodeType.FOOTNOTE, 0, true);
footnote.getFirstParagraph().getRuns().get(1).setText("Edited endnote text.");
// Edit the table
Table table = (Table) docEdited.getChild(NodeType.TABLE, 0, true);
table.getFirstRow().getCells().get(1).getFirstParagraph().getRuns().get(0).setText("Edited Cell 2 contents");
// Edit the textbox
textBox = (Shape) docEdited.getChild(NodeType.SHAPE, 0, true);
textBox.getFirstParagraph().getRuns().get(0).setText("Edited textbox contents");
// Edit the DATE field
FieldDate fieldDate = (FieldDate) docEdited.getRange().getFields().get(0);
fieldDate.setUseLunarCalendar(true);
// Edit the comment
Comment comment = (Comment) docEdited.getChild(NodeType.COMMENT, 0, true);
comment.getFirstParagraph().getRuns().get(0).setText("Edited comment.");
// Edit the header
docEdited.getFirstSection().getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY).getFirstParagraph().getRuns().get(0).setText("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();
compareOptions.setIgnoreFormatting(false);
compareOptions.setIgnoreCaseChanges(false);
compareOptions.setIgnoreComments(false);
compareOptions.setIgnoreTables(false);
compareOptions.setIgnoreFields(false);
compareOptions.setIgnoreFootnotes(false);
compareOptions.setIgnoreTextboxes(false);
compareOptions.setIgnoreHeadersAndFooters(false);
compareOptions.setTarget(ComparisonTargetType.NEW);
docOriginal.compare(docEdited, "John Doe", new Date(), compareOptions);
docOriginal.save(getArtifactsDir() + "Document.CompareOptions.docx");
getTarget/setTarget | |
public int getTarget() / public void setTarget(int value)
|
-
Specifies which document shall be used as a target during comparison.
The value of the property is ComparisonTargetType integer constant.
Example:
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.startTable();
builder.insertCell();
builder.write("Original cell 1 text");
builder.insertCell();
builder.write("Original cell 2 text");
builder.endTable();
// Insert a textbox
Shape textBox = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 20.0);
builder.moveTo(textBox.getFirstParagraph());
builder.write("Original textbox contents");
// Insert a DATE field
builder.moveTo(docOriginal.getFirstSection().getBody().appendParagraph(""));
builder.insertField(" DATE ");
// Insert a comment
Comment newComment = new Comment(docOriginal, "John Doe", "J.D.", new Date());
newComment.setText("Original comment.");
builder.getCurrentParagraph().appendChild(newComment);
// Insert a header
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
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.deepClone(true);
Paragraph firstParagraph = docEdited.getFirstSection().getBody().getFirstParagraph();
// Change the formatting of the first paragraph, change casing of original characters and add text
firstParagraph.getRuns().get(0).setText("hello world! this is the first paragraph, after editing.");
firstParagraph.getParagraphFormat().setStyle(docEdited.getStyles().getByStyleIdentifier(StyleIdentifier.HEADING_1));
// Edit the footnote
Footnote footnote = (Footnote) docEdited.getChild(NodeType.FOOTNOTE, 0, true);
footnote.getFirstParagraph().getRuns().get(1).setText("Edited endnote text.");
// Edit the table
Table table = (Table) docEdited.getChild(NodeType.TABLE, 0, true);
table.getFirstRow().getCells().get(1).getFirstParagraph().getRuns().get(0).setText("Edited Cell 2 contents");
// Edit the textbox
textBox = (Shape) docEdited.getChild(NodeType.SHAPE, 0, true);
textBox.getFirstParagraph().getRuns().get(0).setText("Edited textbox contents");
// Edit the DATE field
FieldDate fieldDate = (FieldDate) docEdited.getRange().getFields().get(0);
fieldDate.setUseLunarCalendar(true);
// Edit the comment
Comment comment = (Comment) docEdited.getChild(NodeType.COMMENT, 0, true);
comment.getFirstParagraph().getRuns().get(0).setText("Edited comment.");
// Edit the header
docEdited.getFirstSection().getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY).getFirstParagraph().getRuns().get(0).setText("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();
compareOptions.setIgnoreFormatting(false);
compareOptions.setIgnoreCaseChanges(false);
compareOptions.setIgnoreComments(false);
compareOptions.setIgnoreTables(false);
compareOptions.setIgnoreFields(false);
compareOptions.setIgnoreFootnotes(false);
compareOptions.setIgnoreTextboxes(false);
compareOptions.setIgnoreHeadersAndFooters(false);
compareOptions.setTarget(ComparisonTargetType.NEW);
docOriginal.compare(docEdited, "John Doe", new Date(), compareOptions);
docOriginal.save(getArtifactsDir() + "Document.CompareOptions.docx");
See Also:
Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
Aspose.Words Support Forum - our preferred method of support.