DEV Community

CodeSharing
CodeSharing

Posted on • Edited on

Accept or Reject Tracked Changes in Word Using Java

If you are collaborating with multiple people on contracts or school assignments, tracking changes can be very useful because it helps you to review each change made by other people, and you can decide whether to accept or reject those changes. In this article, I will share how to accept or reject all tracked changes in a Word document using Free Spire.Doc for Java.

Import Jar Dependency (2 methods)
● Download the Free Spire.Doc for Java and unzip it, then add the Spire.Doc.jar file to your Java application as dependency.

● Directly add the jar dependency to maven project by adding the following configurations to the pom.xml.

<repositories>
   <repository>
      <id>com.e-iceblue</id>
      <name>e-iceblue</name>
      <url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
   </repository>
</repositories>
<dependencies>
   <dependency>
      <groupId>e-iceblue</groupId>
      <artifactId>spire.doc.free</artifactId>
      <version>3.9.0</version>
   </dependency>
</dependencies>
Enter fullscreen mode Exit fullscreen mode

Sample Code

import com.spire.doc.Document;
import com.spire.doc.FileFormat;

public class AcceptOrRejectChanges {

    public static void main(String[] args) {

        //Create a Document object
        Document doc = new Document();

        //Load the sample Word file
        doc.loadFromFile("Oscar Wilde.docx");

        //Accept all changes in the entire document
        doc.acceptChanges();

        ////Reject all changes in the entire document
        //doc.rejectChanges();

        //Save the document
        doc.saveToFile("AcceptAllChanges.docx", FileFormat.Docx);
    }
}
Enter fullscreen mode Exit fullscreen mode

Before
Tracked Changes

After
Accept Changes

Top comments (0)