title: Reading Excel Rows and Columns
body: <p>The code below is to read a large excel file. I got an "Cannot get a text value from a numeric cell at org.apache.poi.hssf.usermodel.HSSFCell.typeMismatch" error. How do I fix this. Column 1 is Numerical Value, Column 2 is String Value.         </p>
  
  <pre><code>    import org.apache.poi.hssf.usermodel.HSSFWorkbook;   
      import org.apache.poi.hssf.usermodel.HSSFSheet;   
      import org.apache.poi.hssf.usermodel.HSSFRow;   
      import org.apache.poi.hssf.usermodel.HSSFCell;   
      import java.io.FileInputStream;   
      import java.io.IOException;   
      import java.util.Iterator;   
      import java.util.Vector;   
  
      public class ReadExcel {   
  
          public static void main(String[] args) throws Exception {   
  
              String filename = "C:/Documents and Settings/oemiola/My Documents/Defects_Input.xls";   
              FileInputStream fis = null;   
  
              try {   
                  fis = new FileInputStream(filename);   
                  HSSFWorkbook workbook = new HSSFWorkbook(fis);   
                  HSSFSheet sheet = workbook.getSheetAt(0);   
                  Iterator rowIter = sheet.rowIterator();    
  
                  while(rowIter.hasNext()){   
                      HSSFRow myRow = (HSSFRow) rowIter.next();   
                      Iterator cellIter = myRow.cellIterator();   
                      Vector&lt;String&gt; cellStoreVector=new Vector&lt;String&gt;();   
                      while(cellIter.hasNext()){   
                          HSSFCell myCell = (HSSFCell) cellIter.next();   
                          String cellvalue = myCell.getStringCellValue();   
                          cellStoreVector.addElement(cellvalue);   
                      }   
                      String firstcolumnValue = null;   
                      String secondcolumnValue = null;   
  
                      int i = 0;   
                      firstcolumnValue = cellStoreVector.get(i).toString();    
                      secondcolumnValue = cellStoreVector.get(i+1).toString();   
  
                      insertQuery(firstcolumnValue,secondcolumnValue);   
                 }   
  
              } catch (IOException e) {   
  
                  e.printStackTrace();   
  
              } finally {   
  
                  if (fis != null) {   
  
                      fis.close();   
                  }   
              }   
  
          }   
  
          private static void insertQuery(String firstcolumnvalue,String secondcolumnvalue) {   
  
              System.out.println(firstcolumnvalue +  " "  +secondcolumnvalue);   
  
  
          }   
  
      }  
  </code></pre>