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

How to get Excel Workbook Sheet names 

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 names of all spread sheets in an Excel workbook.

sheet-names.gif

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

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

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

public class GetSheetNamesTest {

  /**
   @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());
  
    String [] sheetNames = workbook.getSheetNames();
    
    for (int i = ; i < sheetNames.length ; i ++ ) {
      System.out.println("Sheet Name[" + i + "] = " + sheetNames[i]);
    }
    
    //Close and free allocated memory 
    workbook.close()
  }

}
   

It gives the following output,
Number of sheets in this workbook : 3
Sheet Name[0] = ABCD
Sheet Name[1] = PQR
Sheet Name[2] = XYZ


                    Print

   



Books Recommendation

 
 
bl  br