how to read values of FormulaNumberCell of an excel file via jexcel

how to read values of FormulaNumberCell of an excel file via jexcel

Previous Home Next

 

This example demonstrates how to read the values from a FormulaNumberCell of an excel worksheet using the JExcel API. 

To read a workbook you have to import the jxl.read.biff package.
 To display the value contained in the Formula Number Cell we have used the getValue() method on the cell.

In this program we have created a class named ReadNumberFormulaCellSheetXL class, whose main method contains the code for reading the Number Cells and FormulaNumberCells of an 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 ReadNumberFormulaCellSheetXL {

	/**
	 * @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 by doing proper casting
        	System.out.println(nc.getValue());                   // printing the value contained int the cell
        	nc=(NumberCell)readsheet.getCell(0,2);
        	System.out.println(nc.getValue());
        	NumberFormulaCell nfc=(NumberFormulaCell)readsheet.getCell(0, 3); // getting the FormulaNumberCell of sheet via getCell()method
        	System.out.println(nfc.getValue());                            //printing the value
        	
        	
        	
        	
        	
        	
        	
        }
        catch(IOException e)
        {
        	e.printStackTrace();
        }
       
        catch(BiffException e)
        {
        	e.printStackTrace();
        }
	}

}


Previous Home Next