tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Excel > JExcel API > How to read Cell Contents of Excel Spreadsheet

How to read Cell Contents of 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 read the contents of a given Cell as a String.

test.gif

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

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

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

public class GetCellContentTest {

  /**
   @param args
   @throws IOException 
   @throws BiffException 
   */
  public static void main(String[] argsthrows BiffException, IOException {
    Workbook workbook = Workbook.getWorkbook(new File("C:/JXL/Test.xls"));
    Sheet firstSheet = workbook.getSheet(0)
    
    Cell a1 = firstSheet.getCell(0,0);
    Cell b2 = firstSheet.getCell(1,1);
    Cell c3 = firstSheet.getCell(2,2);

    String stringa1 = a1.getContents();
    String stringb2 = b2.getContents();
    String stringc3 = c3.getContents()
    
    System.out.println(stringa1);
    System.out.println(stringb2);
    System.out.println(stringc3);
    
    //Close and free allocated memory 
    workbook.close()
    
  }

}
   

It gives the following output,
A1 data
B2 data
C3 data



 
  


  
bl  br