Jexcel

Java Excel API Projects

Java Excel API Project 1

how to get no of columns, rows , images in an excel sheet using jexce
Previous Home Next

 

This example will show you how to get the number of columns, rows and images in an existing workbook.

To read a workbook you have to import jxl.read.biff package.
 To get the number of columns you should use the getColumns() method, for getting the number of rows you should use the getRows(), and for images use the NumberOfImages() method.

In the following code snippet we have created the GetRowColsInSheetXL class, in which we have created a main class, which contains the code for getting the number of rows, columns and images in the worksheet.

 

package r4r.co.in;
import jxl.*;
import jxl.biff.formula.FormulaException;
import jxl.read.biff.*;
import java.io.File;
import java.io.IOException;
import jxl.write.WriteException;
import java.util.Locale;

public class GetRowColsInSheetXL {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException, WriteException, BiffException, FormulaException{
		// 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
        	int columns=readsheet.getColumns();
            int rows=readsheet.getRows();
        	int noifimgs=readsheet.getNumberOfImages();
        	System.out.println("No. colums in sheet is :"+columns);
        	System.out.println("No. rows in sheet is :"+rows);
        	System.out.println("No of images in the sheet are:"+noifimgs);
        	
       }
        catch(IOException e)
        {
        	e.printStackTrace();
        }
     
        catch(BiffException e)
        {
        	e.printStackTrace();
        }
      
	}

}



Previous Home Next