0

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

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by jaka.ramdani
0

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/

-1

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

Votes + Comments
For providing code, when she has already been warned against it
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.