tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Excel > JExcel API > How to Add Hyperlink to Excel Spreadsheet

How to Add Hyperlink to Excel Spreadsheet 

Java Excel API is an open source java library to read, write and modify Excel spread sheets. This requires the library jxl-2.6.12.jar to be in classpath. The following example shows how to add Hyperlink to Excel Spread sheet.

File Name  :  
com/bethecoder/tutorials/jexcelapi/write/HyperlinkTest.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.jexcelapi.write;

import java.io.File;
import java.io.IOException;
import java.net.URL;

import jxl.Workbook;
import jxl.read.biff.BiffException;
import jxl.write.WritableHyperlink;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;

public class HyperlinkTest {

  /**
   @param args
   @throws IOException 
   @throws IOException 
   @throws WriteException 
   @throws BiffException 
   */
  public static void main(String[] argsthrows IOException, WriteException {
    //Creates a writable workbook with the given file name
    WritableWorkbook workbook = Workbook.createWorkbook(new File("C:/JXL/Hyperlink.xls"));

    WritableSheet sheet = workbook.createSheet("My Sheet"0);
    
      //Add hyper link
      URL  url = new URL("http://www.bethecoder.com");
      
      //Activate cell A2
      WritableHyperlink wh = new WritableHyperlink(0101, url);
      sheet.addHyperlink(wh);
    
      //Activate cells A4, B4
      WritableHyperlink wh2 = new WritableHyperlink(0313, url);
      sheet.addHyperlink(wh2);
      
      //Activate cells A6, B6, C6
      WritableHyperlink wh3 = new WritableHyperlink(0525, url);
      sheet.addHyperlink(wh3);
      
    //Writes out the data held in this workbook in Excel format
    workbook.write()

    //Close and free allocated memory 
    workbook.close()
  }

}
   

It gives the following output,
hyperlink.gif


                    Print

   



Books Recommendation

 
 
bl  br