public class CompareOptions
Example:
// 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.startTable();
builder.insertCell();
builder.write("Original cell 1 text");
builder.insertCell();
builder.write("Original cell 2 text");
builder.endTable();
// Textbox:
Shape textBox = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 20.0);
builder.moveTo(textBox.getFirstParagraph());
builder.write("Original textbox contents");
// DATE field:
builder.moveTo(docOriginal.getFirstSection().getBody().appendParagraph(""));
builder.insertField(" DATE ");
// Comment:
Comment newComment = new Comment(docOriginal, "John Doe", "J.D.", new Date());
newComment.setText("Original comment.");
builder.getCurrentParagraph().appendChild(newComment);
// Header:
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
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.deepClone(true);
Paragraph firstParagraph = docEdited.getFirstSection().getBody().getFirstParagraph();
firstParagraph.getRuns().get(0).setText("hello world! this is the first paragraph, after editing.");
firstParagraph.getParagraphFormat().setStyle(docEdited.getStyles().getByStyleIdentifier(StyleIdentifier.HEADING_1));
((Footnote)docEdited.getChild(NodeType.FOOTNOTE, 0, true)).getFirstParagraph().getRuns().get(1).setText("Edited endnote text.");
((Table)docEdited.getChild(NodeType.TABLE, 0, true)).getFirstRow().getCells().get(1).getFirstParagraph().getRuns().get(0).setText("Edited Cell 2 contents");
((Shape)docEdited.getChild(NodeType.SHAPE, 0, true)).getFirstParagraph().getRuns().get(0).setText("Edited textbox contents");
((FieldDate)docEdited.getRange().getFields().get(0)).setUseLunarCalendar(true);
((Comment)docEdited.getChild(NodeType.COMMENT, 0, true)).getFirstParagraph().getRuns().get(0).setText("Edited comment.");
docEdited.getFirstSection().getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY).getFirstParagraph().getRuns().get(0).setText("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.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");
Constructor Summary |
---|
Property Getters/Setters Summary | ||
---|---|---|
int | getGranularity() | |
void | setGranularity(intvalue) | |
Specifies whether changes are tracked by character or by word.
Default value is |
||
boolean | getIgnoreCaseChanges() | |
void | setIgnoreCaseChanges(booleanvalue) | |
True indicates that documents comparison is case insensitive. By default comparison is case sensitive. | ||
boolean | getIgnoreComments() | |
void | setIgnoreComments(booleanvalue) | |
Specifies whether to compare differences in comments. By default comments are not ignored. | ||
boolean | getIgnoreDmlUniqueId() | |
void | setIgnoreDmlUniqueId(booleanvalue) | |
Specifies whether to ignore difference in DrawingML unique Id. Default value is false. | ||
boolean | getIgnoreFields() | |
void | setIgnoreFields(booleanvalue) | |
Specifies whether to compare differences in fields. By default fields are not ignored. | ||
boolean | getIgnoreFootnotes() | |
void | setIgnoreFootnotes(booleanvalue) | |
Specifies whether to compare differences in footnotes and endnotes. By default footnotes are not ignored. | ||
boolean | getIgnoreFormatting() | |
void | setIgnoreFormatting(booleanvalue) | |
True indicates that formatting is ignored. By default document formatting is not ignored. | ||
boolean | getIgnoreHeadersAndFooters() | |
void | setIgnoreHeadersAndFooters(booleanvalue) | |
True indicates that headers and footers content is ignored. By default headers and footers are not ignored. | ||
boolean | getIgnoreTables() | |
void | setIgnoreTables(booleanvalue) | |
Specifies whether to compare the differences in data contained in tables. By default tables are not ignored. | ||
boolean | getIgnoreTextboxes() | |
void | setIgnoreTextboxes(booleanvalue) | |
Specifies whether to compare differences in the data contained within text boxes. By default textboxes are not ignored. | ||
int | getTarget() | |
void | setTarget(intvalue) | |
Specifies which document shall be used as a target during comparison. The value of the property is ComparisonTargetType integer constant. |
public int getGranularity() / public void setGranularity(int value)
Example:
Shows to specify a granularity while comparing documents.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 tracking // by character ('Granularity.CharLevel'), or by word ('Granularity.WordLevel'). CompareOptions compareOptions = new CompareOptions(); compareOptions.setGranularity(granularity); docA.compare(docB, "author", new Date(), compareOptions); // The first document's collection of revision groups contains all the differences between documents. RevisionGroupCollection groups = docA.getRevisions().getGroups(); Assert.assertEquals(5, groups.getCount());
public boolean getIgnoreCaseChanges() / public void setIgnoreCaseChanges(boolean value)
Example:
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.startTable(); builder.insertCell(); builder.write("Original cell 1 text"); builder.insertCell(); builder.write("Original cell 2 text"); builder.endTable(); // Textbox: Shape textBox = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 20.0); builder.moveTo(textBox.getFirstParagraph()); builder.write("Original textbox contents"); // DATE field: builder.moveTo(docOriginal.getFirstSection().getBody().appendParagraph("")); builder.insertField(" DATE "); // Comment: Comment newComment = new Comment(docOriginal, "John Doe", "J.D.", new Date()); newComment.setText("Original comment."); builder.getCurrentParagraph().appendChild(newComment); // Header: builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY); 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.deepClone(true); Paragraph firstParagraph = docEdited.getFirstSection().getBody().getFirstParagraph(); firstParagraph.getRuns().get(0).setText("hello world! this is the first paragraph, after editing."); firstParagraph.getParagraphFormat().setStyle(docEdited.getStyles().getByStyleIdentifier(StyleIdentifier.HEADING_1)); ((Footnote)docEdited.getChild(NodeType.FOOTNOTE, 0, true)).getFirstParagraph().getRuns().get(1).setText("Edited endnote text."); ((Table)docEdited.getChild(NodeType.TABLE, 0, true)).getFirstRow().getCells().get(1).getFirstParagraph().getRuns().get(0).setText("Edited Cell 2 contents"); ((Shape)docEdited.getChild(NodeType.SHAPE, 0, true)).getFirstParagraph().getRuns().get(0).setText("Edited textbox contents"); ((FieldDate)docEdited.getRange().getFields().get(0)).setUseLunarCalendar(true); ((Comment)docEdited.getChild(NodeType.COMMENT, 0, true)).getFirstParagraph().getRuns().get(0).setText("Edited comment."); docEdited.getFirstSection().getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY).getFirstParagraph().getRuns().get(0).setText("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.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");
public boolean getIgnoreComments() / public void setIgnoreComments(boolean value)
Example:
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.startTable(); builder.insertCell(); builder.write("Original cell 1 text"); builder.insertCell(); builder.write("Original cell 2 text"); builder.endTable(); // Textbox: Shape textBox = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 20.0); builder.moveTo(textBox.getFirstParagraph()); builder.write("Original textbox contents"); // DATE field: builder.moveTo(docOriginal.getFirstSection().getBody().appendParagraph("")); builder.insertField(" DATE "); // Comment: Comment newComment = new Comment(docOriginal, "John Doe", "J.D.", new Date()); newComment.setText("Original comment."); builder.getCurrentParagraph().appendChild(newComment); // Header: builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY); 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.deepClone(true); Paragraph firstParagraph = docEdited.getFirstSection().getBody().getFirstParagraph(); firstParagraph.getRuns().get(0).setText("hello world! this is the first paragraph, after editing."); firstParagraph.getParagraphFormat().setStyle(docEdited.getStyles().getByStyleIdentifier(StyleIdentifier.HEADING_1)); ((Footnote)docEdited.getChild(NodeType.FOOTNOTE, 0, true)).getFirstParagraph().getRuns().get(1).setText("Edited endnote text."); ((Table)docEdited.getChild(NodeType.TABLE, 0, true)).getFirstRow().getCells().get(1).getFirstParagraph().getRuns().get(0).setText("Edited Cell 2 contents"); ((Shape)docEdited.getChild(NodeType.SHAPE, 0, true)).getFirstParagraph().getRuns().get(0).setText("Edited textbox contents"); ((FieldDate)docEdited.getRange().getFields().get(0)).setUseLunarCalendar(true); ((Comment)docEdited.getChild(NodeType.COMMENT, 0, true)).getFirstParagraph().getRuns().get(0).setText("Edited comment."); docEdited.getFirstSection().getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY).getFirstParagraph().getRuns().get(0).setText("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.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");
public boolean getIgnoreDmlUniqueId() / public void setIgnoreDmlUniqueId(boolean value)
Example:
Shows how to compare documents ignoring DML unique ID.Document docA = new Document(getMyDir() + "DML unique ID original.docx"); Document docB = new Document(getMyDir() + "DML unique ID compare.docx"); // By default, Aspose.Words do not ignore DML's unique ID, and the revisions count was 2. // If we are ignoring DML's unique ID, and revisions count were 0. CompareOptions compareOptions = new CompareOptions(); compareOptions.setIgnoreDmlUniqueId(isIgnoreDmlUniqueId); docA.compare(docB, "Aspose.Words", new Date(), compareOptions); Assert.assertEquals(isIgnoreDmlUniqueId ? 0 : 2, docA.getRevisions().getCount());
public boolean getIgnoreFields() / public void setIgnoreFields(boolean value)
Example:
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.startTable(); builder.insertCell(); builder.write("Original cell 1 text"); builder.insertCell(); builder.write("Original cell 2 text"); builder.endTable(); // Textbox: Shape textBox = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 20.0); builder.moveTo(textBox.getFirstParagraph()); builder.write("Original textbox contents"); // DATE field: builder.moveTo(docOriginal.getFirstSection().getBody().appendParagraph("")); builder.insertField(" DATE "); // Comment: Comment newComment = new Comment(docOriginal, "John Doe", "J.D.", new Date()); newComment.setText("Original comment."); builder.getCurrentParagraph().appendChild(newComment); // Header: builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY); 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.deepClone(true); Paragraph firstParagraph = docEdited.getFirstSection().getBody().getFirstParagraph(); firstParagraph.getRuns().get(0).setText("hello world! this is the first paragraph, after editing."); firstParagraph.getParagraphFormat().setStyle(docEdited.getStyles().getByStyleIdentifier(StyleIdentifier.HEADING_1)); ((Footnote)docEdited.getChild(NodeType.FOOTNOTE, 0, true)).getFirstParagraph().getRuns().get(1).setText("Edited endnote text."); ((Table)docEdited.getChild(NodeType.TABLE, 0, true)).getFirstRow().getCells().get(1).getFirstParagraph().getRuns().get(0).setText("Edited Cell 2 contents"); ((Shape)docEdited.getChild(NodeType.SHAPE, 0, true)).getFirstParagraph().getRuns().get(0).setText("Edited textbox contents"); ((FieldDate)docEdited.getRange().getFields().get(0)).setUseLunarCalendar(true); ((Comment)docEdited.getChild(NodeType.COMMENT, 0, true)).getFirstParagraph().getRuns().get(0).setText("Edited comment."); docEdited.getFirstSection().getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY).getFirstParagraph().getRuns().get(0).setText("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.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");
public boolean getIgnoreFootnotes() / public void setIgnoreFootnotes(boolean value)
Example:
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.startTable(); builder.insertCell(); builder.write("Original cell 1 text"); builder.insertCell(); builder.write("Original cell 2 text"); builder.endTable(); // Textbox: Shape textBox = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 20.0); builder.moveTo(textBox.getFirstParagraph()); builder.write("Original textbox contents"); // DATE field: builder.moveTo(docOriginal.getFirstSection().getBody().appendParagraph("")); builder.insertField(" DATE "); // Comment: Comment newComment = new Comment(docOriginal, "John Doe", "J.D.", new Date()); newComment.setText("Original comment."); builder.getCurrentParagraph().appendChild(newComment); // Header: builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY); 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.deepClone(true); Paragraph firstParagraph = docEdited.getFirstSection().getBody().getFirstParagraph(); firstParagraph.getRuns().get(0).setText("hello world! this is the first paragraph, after editing."); firstParagraph.getParagraphFormat().setStyle(docEdited.getStyles().getByStyleIdentifier(StyleIdentifier.HEADING_1)); ((Footnote)docEdited.getChild(NodeType.FOOTNOTE, 0, true)).getFirstParagraph().getRuns().get(1).setText("Edited endnote text."); ((Table)docEdited.getChild(NodeType.TABLE, 0, true)).getFirstRow().getCells().get(1).getFirstParagraph().getRuns().get(0).setText("Edited Cell 2 contents"); ((Shape)docEdited.getChild(NodeType.SHAPE, 0, true)).getFirstParagraph().getRuns().get(0).setText("Edited textbox contents"); ((FieldDate)docEdited.getRange().getFields().get(0)).setUseLunarCalendar(true); ((Comment)docEdited.getChild(NodeType.COMMENT, 0, true)).getFirstParagraph().getRuns().get(0).setText("Edited comment."); docEdited.getFirstSection().getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY).getFirstParagraph().getRuns().get(0).setText("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.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");
public boolean getIgnoreFormatting() / public void setIgnoreFormatting(boolean value)
Example:
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.startTable(); builder.insertCell(); builder.write("Original cell 1 text"); builder.insertCell(); builder.write("Original cell 2 text"); builder.endTable(); // Textbox: Shape textBox = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 20.0); builder.moveTo(textBox.getFirstParagraph()); builder.write("Original textbox contents"); // DATE field: builder.moveTo(docOriginal.getFirstSection().getBody().appendParagraph("")); builder.insertField(" DATE "); // Comment: Comment newComment = new Comment(docOriginal, "John Doe", "J.D.", new Date()); newComment.setText("Original comment."); builder.getCurrentParagraph().appendChild(newComment); // Header: builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY); 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.deepClone(true); Paragraph firstParagraph = docEdited.getFirstSection().getBody().getFirstParagraph(); firstParagraph.getRuns().get(0).setText("hello world! this is the first paragraph, after editing."); firstParagraph.getParagraphFormat().setStyle(docEdited.getStyles().getByStyleIdentifier(StyleIdentifier.HEADING_1)); ((Footnote)docEdited.getChild(NodeType.FOOTNOTE, 0, true)).getFirstParagraph().getRuns().get(1).setText("Edited endnote text."); ((Table)docEdited.getChild(NodeType.TABLE, 0, true)).getFirstRow().getCells().get(1).getFirstParagraph().getRuns().get(0).setText("Edited Cell 2 contents"); ((Shape)docEdited.getChild(NodeType.SHAPE, 0, true)).getFirstParagraph().getRuns().get(0).setText("Edited textbox contents"); ((FieldDate)docEdited.getRange().getFields().get(0)).setUseLunarCalendar(true); ((Comment)docEdited.getChild(NodeType.COMMENT, 0, true)).getFirstParagraph().getRuns().get(0).setText("Edited comment."); docEdited.getFirstSection().getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY).getFirstParagraph().getRuns().get(0).setText("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.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");
public boolean getIgnoreHeadersAndFooters() / public void setIgnoreHeadersAndFooters(boolean value)
Example:
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.startTable(); builder.insertCell(); builder.write("Original cell 1 text"); builder.insertCell(); builder.write("Original cell 2 text"); builder.endTable(); // Textbox: Shape textBox = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 20.0); builder.moveTo(textBox.getFirstParagraph()); builder.write("Original textbox contents"); // DATE field: builder.moveTo(docOriginal.getFirstSection().getBody().appendParagraph("")); builder.insertField(" DATE "); // Comment: Comment newComment = new Comment(docOriginal, "John Doe", "J.D.", new Date()); newComment.setText("Original comment."); builder.getCurrentParagraph().appendChild(newComment); // Header: builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY); 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.deepClone(true); Paragraph firstParagraph = docEdited.getFirstSection().getBody().getFirstParagraph(); firstParagraph.getRuns().get(0).setText("hello world! this is the first paragraph, after editing."); firstParagraph.getParagraphFormat().setStyle(docEdited.getStyles().getByStyleIdentifier(StyleIdentifier.HEADING_1)); ((Footnote)docEdited.getChild(NodeType.FOOTNOTE, 0, true)).getFirstParagraph().getRuns().get(1).setText("Edited endnote text."); ((Table)docEdited.getChild(NodeType.TABLE, 0, true)).getFirstRow().getCells().get(1).getFirstParagraph().getRuns().get(0).setText("Edited Cell 2 contents"); ((Shape)docEdited.getChild(NodeType.SHAPE, 0, true)).getFirstParagraph().getRuns().get(0).setText("Edited textbox contents"); ((FieldDate)docEdited.getRange().getFields().get(0)).setUseLunarCalendar(true); ((Comment)docEdited.getChild(NodeType.COMMENT, 0, true)).getFirstParagraph().getRuns().get(0).setText("Edited comment."); docEdited.getFirstSection().getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY).getFirstParagraph().getRuns().get(0).setText("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.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");
public boolean getIgnoreTables() / public void setIgnoreTables(boolean value)
Example:
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.startTable(); builder.insertCell(); builder.write("Original cell 1 text"); builder.insertCell(); builder.write("Original cell 2 text"); builder.endTable(); // Textbox: Shape textBox = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 20.0); builder.moveTo(textBox.getFirstParagraph()); builder.write("Original textbox contents"); // DATE field: builder.moveTo(docOriginal.getFirstSection().getBody().appendParagraph("")); builder.insertField(" DATE "); // Comment: Comment newComment = new Comment(docOriginal, "John Doe", "J.D.", new Date()); newComment.setText("Original comment."); builder.getCurrentParagraph().appendChild(newComment); // Header: builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY); 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.deepClone(true); Paragraph firstParagraph = docEdited.getFirstSection().getBody().getFirstParagraph(); firstParagraph.getRuns().get(0).setText("hello world! this is the first paragraph, after editing."); firstParagraph.getParagraphFormat().setStyle(docEdited.getStyles().getByStyleIdentifier(StyleIdentifier.HEADING_1)); ((Footnote)docEdited.getChild(NodeType.FOOTNOTE, 0, true)).getFirstParagraph().getRuns().get(1).setText("Edited endnote text."); ((Table)docEdited.getChild(NodeType.TABLE, 0, true)).getFirstRow().getCells().get(1).getFirstParagraph().getRuns().get(0).setText("Edited Cell 2 contents"); ((Shape)docEdited.getChild(NodeType.SHAPE, 0, true)).getFirstParagraph().getRuns().get(0).setText("Edited textbox contents"); ((FieldDate)docEdited.getRange().getFields().get(0)).setUseLunarCalendar(true); ((Comment)docEdited.getChild(NodeType.COMMENT, 0, true)).getFirstParagraph().getRuns().get(0).setText("Edited comment."); docEdited.getFirstSection().getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY).getFirstParagraph().getRuns().get(0).setText("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.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");
public boolean getIgnoreTextboxes() / public void setIgnoreTextboxes(boolean value)
Example:
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.startTable(); builder.insertCell(); builder.write("Original cell 1 text"); builder.insertCell(); builder.write("Original cell 2 text"); builder.endTable(); // Textbox: Shape textBox = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 20.0); builder.moveTo(textBox.getFirstParagraph()); builder.write("Original textbox contents"); // DATE field: builder.moveTo(docOriginal.getFirstSection().getBody().appendParagraph("")); builder.insertField(" DATE "); // Comment: Comment newComment = new Comment(docOriginal, "John Doe", "J.D.", new Date()); newComment.setText("Original comment."); builder.getCurrentParagraph().appendChild(newComment); // Header: builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY); 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.deepClone(true); Paragraph firstParagraph = docEdited.getFirstSection().getBody().getFirstParagraph(); firstParagraph.getRuns().get(0).setText("hello world! this is the first paragraph, after editing."); firstParagraph.getParagraphFormat().setStyle(docEdited.getStyles().getByStyleIdentifier(StyleIdentifier.HEADING_1)); ((Footnote)docEdited.getChild(NodeType.FOOTNOTE, 0, true)).getFirstParagraph().getRuns().get(1).setText("Edited endnote text."); ((Table)docEdited.getChild(NodeType.TABLE, 0, true)).getFirstRow().getCells().get(1).getFirstParagraph().getRuns().get(0).setText("Edited Cell 2 contents"); ((Shape)docEdited.getChild(NodeType.SHAPE, 0, true)).getFirstParagraph().getRuns().get(0).setText("Edited textbox contents"); ((FieldDate)docEdited.getRange().getFields().get(0)).setUseLunarCalendar(true); ((Comment)docEdited.getChild(NodeType.COMMENT, 0, true)).getFirstParagraph().getRuns().get(0).setText("Edited comment."); docEdited.getFirstSection().getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY).getFirstParagraph().getRuns().get(0).setText("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.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");
public int getTarget() / public void setTarget(int value)
Example:
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.startTable(); builder.insertCell(); builder.write("Original cell 1 text"); builder.insertCell(); builder.write("Original cell 2 text"); builder.endTable(); // Textbox: Shape textBox = builder.insertShape(ShapeType.TEXT_BOX, 150.0, 20.0); builder.moveTo(textBox.getFirstParagraph()); builder.write("Original textbox contents"); // DATE field: builder.moveTo(docOriginal.getFirstSection().getBody().appendParagraph("")); builder.insertField(" DATE "); // Comment: Comment newComment = new Comment(docOriginal, "John Doe", "J.D.", new Date()); newComment.setText("Original comment."); builder.getCurrentParagraph().appendChild(newComment); // Header: builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY); 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.deepClone(true); Paragraph firstParagraph = docEdited.getFirstSection().getBody().getFirstParagraph(); firstParagraph.getRuns().get(0).setText("hello world! this is the first paragraph, after editing."); firstParagraph.getParagraphFormat().setStyle(docEdited.getStyles().getByStyleIdentifier(StyleIdentifier.HEADING_1)); ((Footnote)docEdited.getChild(NodeType.FOOTNOTE, 0, true)).getFirstParagraph().getRuns().get(1).setText("Edited endnote text."); ((Table)docEdited.getChild(NodeType.TABLE, 0, true)).getFirstRow().getCells().get(1).getFirstParagraph().getRuns().get(0).setText("Edited Cell 2 contents"); ((Shape)docEdited.getChild(NodeType.SHAPE, 0, true)).getFirstParagraph().getRuns().get(0).setText("Edited textbox contents"); ((FieldDate)docEdited.getRange().getFields().get(0)).setUseLunarCalendar(true); ((Comment)docEdited.getChild(NodeType.COMMENT, 0, true)).getFirstParagraph().getRuns().get(0).setText("Edited comment."); docEdited.getFirstSection().getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY).getFirstParagraph().getRuns().get(0).setText("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.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");