Skip to content
Related Articles

Related Articles

How to Add Hyperlink to the Contents of a Cell using Java?

Improve Article
Save Article
  • Last Updated : 17 Dec, 2020
Improve Article
Save Article

Add a hyperlink to a content of the cell using Java and Apache POI. Apache POI is a Java library that is used to handle Microsoft Office Documents. 


There are two ways to install the Apache POI dependency in our java project:

  1. Download below mentioned Jar files from
  2. Maven Dependency: Set the following dependency in the maven project as:

Environment Setup:

  • Make a project Using java maven.
  • Go to and add the dependency into your project. By this, the libraries get imported into your project.
  • Now, make a java class under com.mycompany.<Your Project Name> in Source Packages.
  • Nice, now you can use the libraries.


  • Create a workbook.
  • Create a spreadsheet in workbook.
  • Create a cell and add color, content and styling to it.
  • Add the address and apply the link colors to it.
  • Add cell in spreadsheet.
  • Repeat step 3 to 5 to write more data

Below is the implementation of the above approach:


// How to add hyperlink to the
// contents of a cell using Java?
import org.apache.poi.common.usermodel.Hyperlink;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFHyperlink;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class HyperLink {
    public static void addLink()
        // Create a Workbook
        XSSFWorkbook myWorkbook = new XSSFWorkbook();
        // Create a Spread Sheet
        XSSFSheet newSpreadsheet
            = myWorkbook.createSheet("Custom Links");
        XSSFCell cell;
        // Create Helpers
        CreationHelper helper
            = myWorkbook.getCreationHelper();
        XSSFCellStyle linkStyle
            = myWorkbook.createCellStyle();
        XSSFFont linkFont = myWorkbook.createFont();
        // Setting the Link Style
        // Adding a Link
        cell = newSpreadsheet.createRow(1).createCell(
        XSSFHyperlink link
            = (XSSFHyperlink)helper.createHyperlink(
        // Writing the File
        FileOutputStream output = new FileOutputStream(
            new File("C:/HyperLink.xlsx"));
        // Writing the content
    public static void main(String[] args) throws Exception


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!