DEV Community

CodeSharing
CodeSharing

Posted on • Edited on

2 2

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

API Trace View

How I Cut 22.3 Seconds Off an API Call with Sentry

Struggling with slow API calls? Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs