繁体   English   中英

尽管添加了dateformatter,但仍无法从数字单元格中获取文本值

[英]Cannot get a text value from a numeric cell despite adding dateformatter

无法从数字单元格获取文本值。

使用日期格式化程序,但无法解决。

也转换为字符串。 那也不是很好。

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);
}

接下来我该怎么办?

你可以这样尝试

    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);
                }
          }
    }

我只是打印了单元格值,如果需要,请捕获它们为字符串,并可以在webdriver命令中使用。

谢谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM