Cannot get a text value from a numeric cell “Poi”

前端 未结 11 1890
余生分开走
余生分开走 2020-12-07 22:17

I\'m trying to consume data from a spreadsheet in Excel, but always of this error, already tried formatting the worksheet to text and number and still the error persists.

相关标签:
11条回答
  • 2020-12-07 23:12

    Using the DataFormatter this issue is resolved. Thanks to "Gagravarr" for the initial post.

    DataFormatter formatter = new DataFormatter();
    
    String empno = formatter.formatCellValue(cell0);
    
    0 讨论(0)
  • 2020-12-07 23:15

    This is one of the other method to solve the Error: "Cannot get a text value from a numeric cell “Poi”"

    Go to the Excel Sheet. Drag and Select the Numerics which you are importing Data from the Excel sheet. Go to Format > Number > Then Select "Plain Text" Then Export as .xlsx. Now Try to Run the Script

    Hope works Fine...!

    Cannot get a text value from a numeric cell “Poi”.img

    0 讨论(0)
  • 2020-12-07 23:15

    This will work:

    WebElement searchbox = driver.findElement(By.name("j_username"));
    WebElement searchbox2 = driver.findElement(By.name("j_password"));         
    
    
    try {
    
          FileInputStream file = new FileInputStream(new File("C:\\paulo.xls")); 
          HSSFWorkbook workbook = new HSSFWorkbook(file);
    
          HSSFSheet sheet = workbook.getSheetAt(0);
    
        for (int i=1; i <= sheet.getLastRowNum(); i++){
    
                HSSFCell j_username = sheet.getRow(i).getCell(0)
                HSSFCell j_password = sheet.getRow(i).getCell(0)
    
                //Setting the Cell type as String
                j_username.setCellType(j_username.CELL_TYPE_STRING)
                j_password.setCellType(j_password.CELL_TYPE_STRING)
    
                searchbox.sendKeys(j_username.toString());
                searchbox2.sendKeys(j_password.toString());
    
    
                searchbox.submit();       
    
                driver.manage().timeouts().implicitlyWait(10000, TimeUnit.MILLISECONDS);
    
        }
    
          workbook.close();
          file.close();
    
         } catch (FileNotFoundException fnfe) {
          fnfe.printStackTrace();
         } catch (IOException ioe) {
          ioe.printStackTrace();
         }
    
    0 讨论(0)
  • 2020-12-07 23:16

    Formatter will work fine in this case.

    import org.apache.poi.ss.usermodel.DataFormatter;
    
    FileInputStream fis = new FileInputStream(workbookName);
    Workbook workbook = WorkbookFactory.create(fis);
    Sheet sheet = workbook.getSheet(sheetName);
    DataFormatter formatter = new DataFormatter();
    String val = formatter.formatCellValue(sheet.getRow(row).getCell(col));
    list.add(val);   //Adding value to list
    
    0 讨论(0)
  • 2020-12-07 23:16

    use the code
    cell.setCellType(Cell.CELL_TYPE_STRING);
    before reading the string value, Which can help you.
    I am using POI version 3.17 Beta1 version, sure the version compatibility also..

    0 讨论(0)
提交回复
热议问题