tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Excel > JExcel API > How to get Excel Workbook Sheet by name

How to get Excel Workbook Sheet by name 

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 get the Excel workbook spread sheet by its name.

sheet-names.gif

File Name  :  
com/bethecoder/tutorials/jexcelapi/read/GetSheetsByNameTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.jexcelapi.read;

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

import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class GetSheetsByNameTest {

  /**
   @param args
   @throws IOException 
   @throws BiffException 
   */
  public static void main(String[] argsthrows BiffException, IOException {
    //Read the given XL sheet 
    Workbook workbook = Workbook.getWorkbook(new File("C:/JXL/Sheet-Names.xls"));
    System.out.println("Number of sheets in this workbook : " + workbook.getNumberOfSheets());
    
    Sheet sheetABCD = workbook.getSheet("ABCD");
    System.out.println(sheetABCD.getName());
    
    Sheet sheetPQR = workbook.getSheet("PQR");
    System.out.println(sheetPQR.getName());
    
    Sheet sheetXYZ = workbook.getSheet("XYZ");
    System.out.println(sheetXYZ.getName());
    
    //Close and free allocated memory 
    workbook.close()
  }

}
   

It gives the following output,
Number of sheets in this workbook : 3
ABCD
PQR
XYZ



 
  


  
bl  br