0

Cannot get a text value from a numeric cell.

Used date formatter and it didn't work out.

Converted to string as well. That too didn't work well.

if(isCellEmpty(sheet.getRow(i).getCell(j)))
{   
    System.out.println("Phone Number field is empty " +i +" " +j +" ================================================>");
    break;
}
else {     
    DataFormatter formatter = new DataFormatter();
    Cell cell = sheet.getRow(i).getCell(j);
    String pass = formatter.formatCellValue(cell);
    Thread.sleep(2000);   

   /*Cell cell = sheet.getRow(i).getCell(j);
   double a=(double) cell.getNumericCellValue();
   String n=Double.toString(a);*/

   driver.findElement(Appointment.PhoneNumber).sendKeys(pass);
}

What should I do next?

centic
  • 15,565
  • 9
  • 68
  • 125
Robert Dsilva
  • 81
  • 1
  • 2
  • 10
  • 1
    what input you want? where you want? can you please share any HTML code or link so we can help you better – Shubham Jain Jan 19 '16 at 14:01
  • 1
    You need to provide snippet of your code if you really want some help – Wins Jan 19 '16 at 14:09
  • @ShubhamJain Please find the edited query! I'm reading from excel phone number and entering.. – Robert Dsilva Jan 20 '16 at 05:02
  • incomplete code i guess..not sure what does appointment.phonenumber is also..can you try to replicate your issue on a public url with small basic working code – Mrunal Gosar Jan 20 '16 at 06:42
  • 1
    @RobertDsilva Put this line `System.out.println(pass + " " + i + " " +j);` after reading the cell value and give us the output. Are there any error messages? If so, please add. By the way: tagging your question properly is the key to getting help quickly. Your question is about poi-hssf, I guess. So this should appear as tag (and in title of your question). – Würgspaß Jan 20 '16 at 06:49
  • @Würgspaß Got it! I was using poi! Was getting and error that can't convert a numeric cell to string. Got my problem resolved and the main prob was that the checking of null with the excel was not proper. Thanks for the help guys! – Robert Dsilva Jan 20 '16 at 08:46
  • @RobertDsilva Nice to hear. If you solved the problem yourself, you should add your solution as an answer and accept it (by clicking on the checkmark) so that others may learn from it. Apart from that it would be nice to add the error details to your question. – Würgspaß Jan 20 '16 at 08:57
  • Found too many ways in which a cell can be checked whether it's null or not but in my case this was very helpful if(pass == null || pass.length() == 0) – Robert Dsilva Jan 20 '16 at 09:03

1 Answers1

0

You can try like this

    for(int i=0; i<sheet.getLastRowNum(); i++){

        Row row =sheet.getRow(i);

          for(int j=0; j<row.getLastCellNum(); j++){

              Cell cell=row.getCell(j);

              if(cell==null){
                  System.out.println("null cell at row " +i +" cell no "+j);
              }

                if(cell.getCellType()==Cell.CELL_TYPE_STRING){


                    System.out.println(cell.getStringCellValue());
                }

                if(cell.getCellType()==Cell.CELL_TYPE_NUMERIC){

                    System.out.println(String.valueOf(cell.getNumericCellValue()));
                }

                if(cell.getCellType()==Cell.CELL_TYPE_BLANK){

                     System.out.println("blank cell at row " +i +" cell no "+j);
                }
          }
    }

i just printed cell values, if required please catch them into string and can be used in webdriver commands.

Thanks

murali selenium
  • 3,847
  • 2
  • 11
  • 20