tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Excel > JExcel API > How to load Excel Workbook from a Stream

How to load Excel Workbook from a Stream 

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 load an Excel workbook from a Stream.

sheet-names.gif

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

import java.io.IOException;

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

public class LoadWBFromStreamTest {

  /**
   @param args
   @throws IOException 
   @throws BiffException 
   */
  public static void main(String[] argsthrows BiffException, IOException {
    //Read the given XL sheet 
    Workbook workbook = Workbook.getWorkbook(
        LoadWBFromStreamTest.class.getClassLoader()
        .getResourceAsStream("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