Saturday 23 January 2016

How to search the string in perticular excel sheet using Apche POI



    public int findString(String FilePath,String SheetName,String Text) throws IOException
    {
        FileInputStream fsIP= new FileInputStream(new File(FilePath));
        HSSFWorkbook wb = new HSSFWorkbook(fsIP); //Access the workbook
//        HSSFSheet worksheet = wb.getSheet("TestData"); //Access the worksheet, so that we can update / modify it.
        HSSFSheet worksheet = wb.getSheet(SheetName);
       
          for (Row row : worksheet) {
              for (Cell cell : row) {
                  if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
                      if (cell.getRichStringCellValue().getString().trim().equals(Text)) {
                          return row.getRowNum();
                       
                      }
                  }
              }
          }
        return 0;
                    
     
    }
   


Note : Please use latest Apache POI for using this code or use Apache poi files which are supports all predefined functions.

No comments:

Post a Comment