Hi all I need to read an Excel sheet using java and I need to know how many columns are there in that excel sheet. Please drop a code snippet to this thread

Hi all I need to read an Excel sheet using java and I need to know how many columns are there in that excel sheet. Please drop a code snippet to this thread

Don't ask lamely for ready-made code snippets no one's going to give you that.

If you are ready to do something for your self take a look here : http://poi.apache.org/

Hi all I need to read an Excel sheet using java and I need to know how many columns are there in that excel sheet. Please drop a code snippet to this thread

Try using JXL. Below some simple approach for getting total rows and columns of a Worksheet in an Excel file.

import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

/**
 *
 * @author jaka
 */
public class Jxl1 {

    public static void main(String args[]) {
        try {
            File excelFile = new File("C:\\sample-file.xls");
            Workbook wb = Workbook.getWorkbook(excelFile);
            Sheet sheet = wb.getSheet(1);
            int column = sheet.getColumns();
            int row = sheet.getRows();

            System.out.println("Total Columns: " + column);
            System.out.println("Total Rows: " + row);
        } catch (IOException ex) {
            Logger.getLogger(Jxl1.class.getName()).log(Level.SEVERE, null, ex);
        } catch (BiffException ex) {
            Logger.getLogger(Jxl1.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

hope will help ..

-jaka

commented: For providing code, when she has already been warned against it -1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.