Java modifying and deleting excel hyperlinks

Time:2020-9-28

In the previous article, I described how to add text links and picture links to EXCEL documents. This tutorial demonstrates how toModify and delete existing hyperlinks in Excel

The tools used in this code demonstration are stillFree Spire.XLS for Java。 The product package can be downloaded from the official website. After decompressing, the Spire.Xls.jar Import it into idea manually.

Of course, it can also be done throughmavenWarehouse to import products and related dependencies. Please click this link to view the related tutorial.

Example 1 modifying hyperlinks

import com.spire.xls.*;
import com.spire.xls.collections.HyperLinksCollection;
public class ModifyHyperlink {
    public static void main(String[] args) {
        //Load sample excel document
 Workbook workbook = new Workbook();
        workbook.loadFromFile("C:UsersTest1DesktopSample.xlsx");
        //Read the first sheet
 Worksheet sheet = workbook.getWorksheets().get(0);
        //Get hyperlink, modify text information and link address
 HyperLinksCollection links = sheet.getHyperLinks();
        links.get (0). Settexttodisplay ("Purple month company revenue statistics");
        links.get(0).setAddress("https://www.11467.com/qiye/80122421.htm");
        //Save the document
 workbook.saveToFile("output/ModifyHyperlink.xlsx", ExcelVersion.Version2013);
    }
}

Comparison of modification results:

Java modifying and deleting excel hyperlinks

Example 2: deleting hyperlinks

import com.spire.xls.*;
import com.spire.xls.collections.HyperLinksCollection;
public class RemoveHyperlink {
    public static void main(String[] args) {
        //Load sample excel document
 Workbook workbook = new Workbook();
        workbook.loadFromFile("C:UsersTest1DesktopSample.xlsx");
        //Get first sheet
 Worksheet sheet = workbook.getWorksheets().get(0);
        //Gets the hyperlink in the worksheet
 HyperLinksCollection links = sheet.getHyperLinks();
        //Remove hyperlinks and keep text information
 sheet.getHyperLinks().removeAt(0);
        //Save the document
 String output = "output/RemoveHyperlink.xlsx";
        workbook.saveToFile(output, ExcelVersion.Version2013);
    }
}

Comparison of deletion results:

Java modifying and deleting excel hyperlinks

(end of this article)