Related blog post: Compare Word Documents using C#
Last active
April 18, 2023 08:01
-
-
Save GroupDocsGists/2bc5a8376473a179e59310fd3dc23a9f to your computer and use it in GitHub Desktop.
Compare Word Documents, Find Differences, and Accept or Reject Changes using C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Accept and reject identified changes by comparing Word documents using C# | |
*/ | |
using (Comparer comparer = new Comparer("path/document-1.docx")) | |
{ | |
comparer.Add("path/document-2.docx"); | |
comparer.Compare(); | |
ChangeInfo[] changes = comparer.GetChanges(); | |
// Rejecting the first identified change and it will not be added to result document | |
changes[0].ComparisonAction = ComparisonAction.Reject; | |
comparer.ApplyChanges("path/rejected-change-result.docx", new ApplyChangeOptions { Changes = changes, SaveOriginalState = true }); | |
changes = comparer.GetChanges(); | |
changes[0].ComparisonAction = ComparisonAction.Accept; | |
comparer.ApplyChanges("path/accepted-change-result.docx", new ApplyChangeOptions { Changes = changes }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Compare Multiple Word Documents using C# | |
*/ | |
using (Comparer comparer = new Comparer("path/document-1.docx")) | |
{ | |
comparer.Add("path/document-2.docx"); | |
comparer.Add("path/document-3.docx"); | |
comparer.Add("path/document-4.docx"); | |
comparer.Compare("path/compare-result.docx"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Compare Password Protected Word Documents using C# | |
*/ | |
using (Comparer comparer = new Comparer("path/protected-document-1.docx", new LoadOptions(){ Password = "SourceFilePassword" })) | |
{ | |
comparer.Add("path/protected-document-2.docx", new LoadOptions() { Password = "TargetFilePassword" }); | |
comparer.Compare("path/compared-protected-docs-result.docx"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Compare Two Word Documents and Highlight Changes using C# | |
*/ | |
using (Comparer comparer = new Comparer("path/document.docx")) | |
{ | |
comparer.Add("path/document-ver2.docx"); | |
comparer.Compare("path/compared-result.docx"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment