Insert Image Hyperlinks in Excel in Java

This article demonstrates how to insert an image into Excel and add a hyperlink to it using Spire.XLS for Java.

import com.spire.xls.*;

public class InsertImageHyperlink {

    public static void main(String[] args) {

        //Create a Workbook instance and get the first worksheet
        Workbook wb = new Workbook();
        Worksheet sheet = wb.getWorksheets().get(0);

        //Insert text in the cell A1
        sheet.getCellRange("A1").setText("Image Hyperlink");
        sheet.getCellRange("A1").getStyle().setVerticalAlignment(VerticalAlignType.Top);

        //Insert an image to the cell A1
        String picPath = "C:\\Users\\Administrator\\Desktop\\logo.png";
        ExcelPicture picture = sheet.getPictures().add(1,1,picPath);

        //Set a hyperlink for the image
        picture.setHyperLink("Http://www.e-iceblue.com", true);

        //Set the column width and row height
        sheet.getColumns()[0].setColumnWidth(22);
        sheet.getRows()[0].setRowHeight(140);
        picture.setTopRowOffset(25);

        //Save the document
        wb.saveToFile("ImageHyperlink.xlsx", ExcelVersion.Version2016);
    }
}

Insert Image Hyperlinks in Excel in Java