Read Data From Excel using POI jars




import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
public class DatafromExcel {     
public static void main(String[] args) throws InvalidFormatException, IOException {     
              //initilize fileInputStream and set path of excel file
              InputStream is=new FileInputStream("G:/Selenium Java Doc/Users/Gtpv/jp/My_Practice/src/DATA.xls");   
              //Create workbook and access file into Workbook
              Workbook wb=WorkbookFactory.create(is); 
              //Get sheet by sending sheet id

              Sheet s=wb.getSheetAt(0);
              //Get row count
              int rc=s.getLastRowNum();
              //Loop for every Row
              for(int j=0;j<rc+1;j++)
              {     
              //Create object for Row and pass which row need to be accessed
              Row r=s.getRow(j);
              //Get Column count
              int cc=r.getLastCellNum();
              //Loop to Every cell
              for(int k=0;k<cc;k++)
              {     
                     //Get Cell data
                     String cellData =r.getCell(k).getStringCellValue();
                     //Print cell data
                     System.out.print(cellData+"  ");
              }
              //New Line
              System.out.println();
       }
       }
}
Output :     USER NAME  PASSWORD 
krishna  gt1234 

reddy  selenium