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

How to read Contents of all Cells in 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 all Cells in a Spread sheet as a String.

test.gif

File Name  :  
com/bethecoder/tutorials/jexcelapi/read/GetCellContentTest2.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 GetCellContentTest2 {

  /**
   @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)
    System.out.println("Rows in first sheet : " + firstSheet.getRows());
    System.out.println("Columns in first sheet : " + firstSheet.getColumns());
    System.out.println();
    
    for (int row = ; row < firstSheet.getRows(); row ++ ) {
      for (int column = ; column < firstSheet.getColumns(); column ++) {
        System.out.print(firstSheet.getCell(column, row).getContents() "\t\t");
      }
      System.out.println();
    }
    
    //Close and free allocated memory 
    workbook.close()
  }

}
   

It gives the following output,
Rows in first sheet : 3
Columns in first sheet : 3

A1 data		B1 data		C1 data		
A2 data		B2 data		C2 data		
A3 data		B3 data		C3 data		



 
  


  
bl  br