Modify and Remove Hyperlinks in Excel Using Java

In the previous article, I’ve introduced how to add hyperlinks to Excel cells and read hyperlinks from an existing Excel document. Now, this article will share how to modify and remove hyperlinks in Excel using Free Spire.XLS for Java.

Installation (2 Method)
1# Download the Free Spire.XLS for Java and unzip it, then add the Spire.Xls.jar file to your project as dependency.

2# You can also 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.xls.free</artifactId>
<version>3.9.1</version>
</dependency>
</dependencies>

Modify hyperlinks

import com.spire.xls.*;
import com.spire.xls.collections.HyperLinksCollection;

public class ModifyHyperlink {
public static void main(String[] args) {
//Create a workbook and load an Excel file
Workbook workbook = new Workbook();
workbook.loadFromFile("Book1.xlsx");

//Get the collection of all hyperlinks in the worksheet
Worksheet sheet = workbook.getWorksheets().get(0);

//Change the values of TextToDisplay and Address property
HyperLinksCollection links = sheet.getHyperLinks();
links.get(0).setTextToDisplay("Germany");
links.get(0).setAddress("https://en.wikipedia.org/wiki/Germany");

//Save the document
workbook.saveToFile("ModifyHyperlink.xlsx", ExcelVersion.Version2013);
}
}

Remove Hyperlinks

import com.spire.xls.*;
import com.spire.xls.collections.HyperLinksCollection;
public class RemoveHyperlink {
public static void main(String[] args) {
//Create a workbook and load an Excel file
Workbook workbook = new Workbook();
workbook.loadFromFile("C:\\Users\\Test1\\Desktop\\Sample.xlsx");

//Get the first worksheet
Worksheet sheet = workbook.getWorksheets().get(0);

//Get the collection of all hyperlinks in the worksheet
HyperLinksCollection links = sheet.getHyperLinks();

//Remove hyperlink and keep link text
sheet.getHyperLinks().removeAt(0);
sheet.getHyperLinks().removeAt(0);

//Save the document
String output = "output/RemoveHyperlink.xlsx";
workbook.saveToFile(output, ExcelVersion.Version2013);
}
}

Sharing Java Code