70
loading...
This website collects cookies to deliver better user experience
Note: The Word Processor (Document Editor) component requires server-side interaction for the following operations: · Open Word documents (converting Word documents to SFDT file format). · Paste content with formatting. · Restrict editing. · Spell checking. Syncfusion provides a server-side library for the following platforms: · ASP.NET Core · ASP.NET MVC · Java You can find the web API projects for the supported platforms in this GitHub repository. |
//Reads the input Word document.
Stream inputStream = File.OpenRead(Path.GetFullPath(@"../../../../../../Data/InputWithTrackedChanges.docx"));
string authorName = "Steven Buchanan";
int acceptedChangesCount = AcceptChanges(inputStream, authorName);
Console.WriteLine("Accepted {0} changes made by {1}.", acceptedChangesCount, authorName);
static int AcceptChanges(Stream inputStream, string authorName)
{
int acceptedChangesCount = 0;
//Creates new Word document instance for Word processing.
using (WordDocument document = new WordDocument())
{
//Opens the Word document containing tracked changes.
document.Open(inputStream, FormatType.Docx);
inputStream.Dispose();
//Iterates all the revisions present in the Word document.
for (int i = document.Revisions.Count - 1; i >= 0; i--)
{
//Validates the author of current revision to accept/reject it.
if (document.Revisions[i].Author == authorName)
{
//Accepts the current revision.
document.Revisions[i].Accept();
acceptedChangesCount++;
}
//Resets i to last item, since accepting one revision will impact all its related revisions and leads to change in Revsions
if (i > document.Revisions.Count - 1)
i = document.Revisions.Count;
}
//Saves the Word document as DOCX format
using (Stream docStream = File.Create(Path.GetFullPath(@"../../../OutputAfterAcceptingChanges.docx")))
{
document.Save(docStream, FormatType.Docx);
}
}
return acceptedChangesCount;
}
//Reads the input Word document.
Stream inputStream = File.OpenRead(Path.GetFullPath(@"../../../../../../Data/InputWithTrackedChanges.docx"));
RevisionType revisionType = RevisionType.Insertions | RevisionType.Deletions;
int rejectedChangesCount = RejectChanges(inputStream, revisionType);
static int RejectChanges(Stream inputStream, RevisionType revisionType)
{
int rejectedChangesCount = 0;
//Creates new Word document instance for Word processing.
using (WordDocument document = new WordDocument())
{
//Opens the Word document containing tracked changes.
document.Open(inputStream, FormatType.Docx);
inputStream.Dispose();
//Iterates all the revisions present in the Word document.
for (int i = document.Revisions.Count - 1; i >= 0; i--)
{
//Validates the revision type of current revision to accept/reject it.
if ((document.Revisions[i].RevisionType & revisionType) != 0)
{
//Rejects the current revision.
document.Revisions[i].Reject();
rejectedChangesCount++;
}
//Resets i to last item, since rejecting one revision will impact all its related revisions. and lead to change in Revsions.
if (i > document.Revisions.Count - 1)
i = document.Revisions.Count;
}
//Saves the Word document as DOCX format.
using (Stream docStream = File.Create(Path.GetFullPath(@"../../../OutputAfterRejectingChanges.docx")))
{
document.Save(docStream, FormatType.Docx);
}
}
return rejectedChangesCount;
}