title: How to iterate over current row in an excel sheet using column name?
body: <p>I need to parse over an excel sheet and retrieve values from each row to store it in database. Currently I am doing it based on the type of values that each cell holds. This is ok in the current case as I have to deal with only 2 columns. But I have a new requirement to parse an excel sheet that holds more than 12 columns. How can it be done in this case? Is there a way I could iterate each row based on column if I am using a structured table with table headers?</p>
  
  <p>My current code is as follows. </p>
  
  <pre><code>        File file = new File(UPLOAD_LOCATION + fileUpload.getFile().getOriginalFilename());
          FileInputStream excelFile = new FileInputStream(file);
  
          Workbook workbook = new XSSFWorkbook(excelFile);
          Sheet datatypeSheet = workbook.getSheetAt(0);
          Iterator&lt;Row&gt; iterator = datatypeSheet.iterator();
          while (iterator.hasNext()) {
              Row currentRow = iterator.next();
              Iterator&lt;Cell&gt; cellIterator = currentRow.iterator();
  
              while (cellIterator.hasNext()) {
  
                  Cell currentCell = cellIterator.next();
                  // getCellTypeEnum shown as deprecated for version 3.15
                  // getCellTypeEnum ill be renamed to getCellType starting
                  // from version 4.0
                  if (currentCell.getCellTypeEnum() == CellType.STRING) {
                      System.out.print(currentCell.getStringCellValue() + "--");
                  } else if (currentCell.getCellTypeEnum() == CellType.NUMERIC) {
                      System.out.print(currentCell.getNumericCellValue() + "--");
                  }
  
              }
  </code></pre>
  
  <p>I am using the following external apache API imports:</p>
  
  <pre><code>import org.apache.poi.ss.usermodel.*;
  import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  </code></pre>
  
  <p>Is there a way I can do the same passing in the name of column headers?</p>
  
  <p>Please help.</p>
  
  <p>Thanks in advance.</p>