how to read NumberCell values of an excel sheet using jexcel

how to read NumberCell values of an excel sheet using jexcel

Previous Home Next

 

This example shows you the way how can you read the values of NumberCells  of an excel worksheet of an existing workbook using the JExcel API.

We have created a class named ReadNumberCellSheetXL, in which we have created a main method which contains the code for reading the value of a NumberCell of a an excel sheet.
 We have used the getValue() method for getting the values contained in the NumberCell of an worksheet.

The following code shows how can we read the numerical values from the excel worksheet.

 

package r4r.co.in;
import jxl.*;
import jxl.Workbook;
import jxl.read.biff.*;
import java.io.File;
import java.io.IOException;
import jxl.write.WriteException;
import java.util.Locale;
public class ReadNumberCellSheetXL {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException, WriteException, BiffException{
		// TODO Auto-generated method stub
        try
        {
        	File f1=new File("F:/JAVA PROJECTS/Jexcel/src/r4r/co/in/firstsheet.xls");
        	WorkbookSettings ws=new WorkbookSettings();
        	ws.setLocale(new Locale("er","ER"));
        	Workbook workbook=Workbook.getWorkbook(f1,ws); //opening an existing workbook 
        	
        	Sheet readsheet=workbook.getSheet(0);
        	System.out.println(readsheet.getName());    // getting the name of sheet contained in the workbook
        	LabelCell lcobj=readsheet.findLabelCell("Sum");    // finding the label name Sum in the sheet
        	System.out.println(lcobj.getString());             // if exists displaying the name of label
        	NumberCell nc=(NumberCell)readsheet.getCell(0,1);   // getting the NumberCell of sheet via getCell() method
        	System.out.println(nc.getValue());                   // printing the value contained int the cell
        	nc=(NumberCell)readsheet.getCell(0,2);
        	System.out.println(nc.getValue());
        }
        catch(IOException e)
        {
        	e.printStackTrace();
        }
        
        catch(BiffException e)
        {
        	e.printStackTrace();
        }
	}

}


Previous Home Next