Class DocxCompare
- Namespace
- DocToolkit
- Assembly
- DocToolkit.Docx.dll
Compares two versions of a document and returns the later one with the differences marked as tracked changes (A118).
public static class DocxCompare
- Inheritance
-
DocxCompare
- Inherited Members
Remarks
The result is an ordinary .docx carrying revisions, not a report — so Word shows it the way it shows any tracked-changes document, and DocxReview reads and applies it without knowing it came from here: Inspect(byte[]) returns a DocxReviewReport whose Revisions lists them, and AcceptRevisions(byte[]) / RejectRevisions(byte[]) resolve them.
Every member named above is a cref, not a code span, on purpose. This paragraph
shipped naming DocxEditor.Revisions — a type that has no such member — and nothing
caught it: a wrong name inside <c> is prose, while a wrong cref is CS1574
and this repository builds with TreatWarningsAsErrors. The package README had it right
the whole time, which is the usual shape of the drift.
Paragraph text is what gets compared, and everything else is REPORTED rather than silently
skipped. Tables, lists and formatting changes are named in the warnings of
CompareWithReport(byte[], byte[], string). A comparison that quietly mis-marked a
table would be worse than one that says what it did not look at — the same contract
DocToDocxConverter offers through LegacyDocOptions.AllowContentLoss.
A formatting-only change is not detected at all, and is not reported as a text change
either. DocxRevisionKind has no formatting member, and inventing one to describe
something this does not measure would be worse than the gap.
Methods
Compare(byte[], byte[], string)
Returns revised with its differences from original
marked as tracked insertions and deletions.
public static byte[] Compare(byte[] original, byte[] revised, string author)
Parameters
originalbyte[]The earlier version.
revisedbyte[]The later version, which the result is built from.
authorstringThe name recorded against each revision.
Returns
- byte[]
Remarks
Only paragraph text is compared. Use CompareWithReport(byte[], byte[], string) to find out what was not — this overload discards that, and a caller who does not know whether the documents contain tables should not be using it.
Comparing a document with itself produces no revisions, rather than a document marked entirely rewritten.
The cost is dominated by the differing text rather than by document size: the shared prefix and suffix are removed first, so two revisions of one document are cheap and two unrelated documents are the bounded worst case.
Exceptions
- ArgumentNullException
Any argument is null.
- ArgumentException
Either document is empty, or
authoris blank.- DocumentConversionException
Either package could not be opened or edited.
CompareWithReport(byte[], byte[], string)
Compares two documents and reports what the comparison did not look at.
public static ConversionResult<byte[]> CompareWithReport(byte[] original, byte[] revised, string author)
Parameters
Returns
- ConversionResult<byte[]>
The marked-up document, with a warning for every construct present but not compared.
HasLossis true whenever anything was skipped, which is the signal that the verdict covers less than the document.
Remarks
Only paragraph text is compared. Use CompareWithReport(byte[], byte[], string) to find out what was not — this overload discards that, and a caller who does not know whether the documents contain tables should not be using it.
Comparing a document with itself produces no revisions, rather than a document marked entirely rewritten.
The cost is dominated by the differing text rather than by document size: the shared prefix and suffix are removed first, so two revisions of one document are cheap and two unrelated documents are the bounded worst case.