954,164 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Read Excel Sheet

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

sneharaveendran
Newbie Poster
3 posts since Apr 2009
Reputation Points: 10
Solved Threads: 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/

verruckt24
Posting Shark
952 posts since Nov 2008
Reputation Points: 485
Solved Threads: 89
 
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

jaka.ramdani
Newbie Poster
18 posts since Sep 2008
Reputation Points: 9
Solved Threads: 3
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You