AdSenseHeader

Reading the Excel Files data using java

When  reading the ".xls" file data  in java. We are Apache POI Api  this poi is used for to read the excel file data .If you want to read the ".xlsx" format file we are adavanced Apache Poi api.

  • First Download the apache poi jar

  • Sample Program for Reading .xls file

Class XlsRead
{
  public static void main(String[] args) throws Exception{

         String filename = "E:\\ramuexcel.xls";
         FileInputStream fis = null;

        try
           {
               fis = new FileInputStream(filename);
             HSSFWorkbook workbook = new HSSFWorkbook(fis);
             HSSFSheet sheet = workbook.getSheetAt(0);
             while (rows.hasNext()) {
                 HSSFRow row = (HSSFRow) rows.next();
               
                 Iterator cells = row.cellIterator();
               
                 while(cells.hasNext())
                 {
                     HSSFCell cell=(HSSFCell) cells.next();
                     if(cell.getCellNum()==3)//Getting 4 th cell data
                     {
                         servicename.add(cell);
                     }
                     if(cell.getCellNum()==6)
                     {
                         serviceDesc.add(cell);
                       }
                   }

            }
        catch(Exception e)
          {
              e.printStackTrace();
           }
     }
}



2 comments:

  1. There is error in program

    ReplyDelete
  2. Good day! I could have sworn I've been to this website before but after reading through some of the post I realized it's new to me. Anyhow, I'm definitely glad I found it and I'll be book-marking and checking back frequently! capitalone.com login

    ReplyDelete

 
Top