title: When getting cell content using Apache-POI Library, I get both "Cannot get a numeric value from a text cell" and the reverse of that. How do I fix it?
body: <p>I realize the question is a little confusing, but I didn't know how else to word it. Anyway, here is the original code:</p>
  
  <pre><code>private void readFile(String excelFileName) throws FileNotFoundException, IOException {
      XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(excelFileName));
      if (workbook.getNumberOfSheets() &gt; 1){
          System.out.println("Please make sure there is only one sheet in the excel workbook.");
      }
      XSSFSheet sheet = workbook.getSheetAt(0);
      int numOfPhysRows = sheet.getPhysicalNumberOfRows();
      XSSFRow row;
      XSSFCell num;
      for(int y = 1;y &lt; numOfPhysRows;y++){    //start at the 2nd row since 1st should be category names
          row = sheet.getRow(y);
          poNum = row.getCell(1);
          item = new Item(Integer.parseInt(poNum.getStringCellValue());
          itemList.add(item);
          y++;
      }
  }
  
  private int poiConvertFromStringtoInt(XSSFCell cell){
      int x = Integer.parseInt(Double.toString(cell.getNumericCellValue()));
      return x;
  }
  </code></pre>
  
  <p>I am getting the following error:</p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalStateException: Cannot get a numeric value from a text cell
      at org.apache.poi.xssf.usermodel.XSSFCell.typeMismatch(XSSFCell.java:781)
      at org.apache.poi.xssf.usermodel.XSSFCell.getNumericCellValue(XSSFCell.java:199)
  </code></pre>
  
  <p>Even if I change it to get either a string using <code>XSSFCell.getStringCellValue()</code> or even <code>XFFSCell.getRichTextValue</code>, I get the reverse of the above error message (and I am making sure to ultimately make it an int using <code>Integer.parseInt(XSSFCell.getStringCellValue()</code>).</p>
  
  <p>The error then reads:</p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalStateException: Cannot get a text value from a numeric cell
      at org.apache.poi.xssf.usermodel.XSSFCell.typeMismatch(XSSFCell.java:781)
      at org.apache.poi.xssf.usermodel.XSSFCell.getNumericCellValue(XSSFCell.java:199)
  </code></pre>
  
  <p>I know for a fact that the excel spreadsheet column is in fact a string. I can't change the excel sheet as it is uploaded else where always using the same format and formatting each column first takes up to much processing time. </p>
  
  <p>Any suggestions?</p>
  
  <p>[Solution] Here is the solution code I came up with from @Wivani's help:</p>
  
  <pre><code>private long poiGetCellValue(XSSFCell cell){
      long x;
      if(cell.getCellType() == 0)
          x = (long)cell.getNumericCellValue();
      else if(cell.getCellType() == 1)
          x = Long.parseLong(cell.getStringCellValue());
      else
          x = -1;
      return x;
  }
  </code></pre>