Your Ad Here



import java.io.IOException;
import java.io.*;
import java.util.Iterator;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFRow;

class Readingexcel
{
public static void main(String[] args)
{
try {
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file location "E:/..excel.xls"));
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(1);
HSSFRow row;
HSSFCell cell;
String s;

int rows; // No of rows
rows = sheet.getPhysicalNumberOfRows();

int cols = 0; // No of columns
int tmp = 0;

// This trick ensures that we get the data properly even if it doesn’t start from first few rows
for(int i = 0; i <>
{
row = sheet.getRow(i);
if(row != null)
{
tmp = sheet.getRow(i).getPhysicalNumberOfCells();
if(tmp > cols) cols = tmp;
}
}

for(int r = 0; r <>
{
row = sheet.getRow(r);
if(row != null)
{
for(int c = 0; c <>
{
cell = row.getCell((short)c);
if(cell != null)
{
// Your code here
// s = cell.getData();
System.out.println(cell);
}
}
}
}
}
catch(Exception ioe)
{
ioe.printStackTrace();
}

}
}

Your Ad Here
Custom Search