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