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 Spreadsheet2

How to Add Hyperlink to Excel Spreadsheet2 

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/HyperlinkTest2.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.jexcelapi.write;

import java.io.File;
import java.io.IOException;

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 HyperlinkTest2 {

  /**
   @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/Hyperlink2.xls"));

    WritableSheet sheet = workbook.createSheet("My Sheet"0);
    
      //Add hyper link
    File file = new File("C:/abcd.txt");
      
      //Activate cell A2
      WritableHyperlink wh = new WritableHyperlink(0101, file, "Test description for link1");
      sheet.addHyperlink(wh);
    
      //Activate cells A4, B4
      WritableHyperlink wh2 = new WritableHyperlink(0313, file, "Test description for link2");
      sheet.addHyperlink(wh2);
      
      //Activate cells A6, B6, C6
      WritableHyperlink wh3 = new WritableHyperlink(0525, file, "Test description for link3");
      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,
hyperlink2.gif


                    Print

   



Books Recommendation

 
 
bl  br