title: How to read values line by line from Excel file, and place them into a Map?
body: <p>My goal is to read an excel document with know format, read each cell and column one at a time. Each row will be set into a bean called Item which will be put into a map with its key as it item number. Once I do this I can continue with the rest of the program and put into a database. I currently a whole column at a time and trying to figure out how to do this.</p>
  
  <pre><code>public class Excel {
  
      private Items items;
  
      Excel(Items items) {
          this.items = items;
      }
  
      public static void main(String[] args) {
  
          JFileChooser fileChooser = new JFileChooser();
          int returnVlue = fileChooser.showOpenDialog(null);
  
          Map&lt;Long, Items&gt; map1 = new HashMap&lt;Long, Items&gt;();
  
          String mat, thick, size, lbsPerSheet, lbs;
  
          if (returnVlue == JFileChooser.APPROVE_OPTION) {
  
              try {
                  Workbook workbook = new HSSFWorkbook(new FileInputStream(
                          fileChooser.getSelectedFile()));
                  Sheet sheet = workbook.getSheetAt(0);
  
                  for (Iterator&lt;Row&gt; rit = sheet.rowIterator(); rit.hasNext();) {
  
                      Row row = rit.next();
  
                      for (Iterator&lt;Cell&gt; cit = row.cellIterator(); cit.hasNext();) {
                          Cell cell = cit.next();
                          cell.setCellType(Cell.CELL_TYPE_STRING);
  
                          mat = cell.getStringCellValue();
                          thick = cell.getStringCellValue();
                          size = cell.getStringCellValue();
                          lbsPerSheet = cell.getStringCellValue();
                          lbs = cell.getStringCellValue();
  
                          System.out.println("Mat "+mat+" Thick "+ thick+" Size "+size+" lbs Per Sheet "+lbsPerSheet+" lbs "+lbs+ "\t");
                      }
                      System.out.println();
  
                  }
  
              } catch (Exception e) {
                  // TODO: handle exception
              }
  
          }
  
      }
  }
  </code></pre>
  
  <p>output</p>
  
  <pre class="lang-none prettyprint-override"><code>Mat 11960120 Thick 11960120 Size 11960120 lbs Per Sheet 11960120 lbs 11960120   
  Mat 0.119 Thick 0.119 Size 0.119 lbs Per Sheet 0.119 lbs 0.119  
  Mat 60x120 Thick 60x120 Size 60x120 lbs Per Sheet 60x120 lbs 60x120 
  Mat 250 Thick 250 Size 250 lbs Per Sheet 250 lbs 250    
  Mat 0.41 Thick 0.41 Size 0.41 lbs Per Sheet 0.41 lbs 0.41   
  
  Row org.apache.poi.hssf.usermodel.HSSFRow@2a
  Mat 18860120 Thick 18860120 Size 18860120 lbs Per Sheet 18860120 lbs 18860120   
  Mat 0.188 Thick 0.188 Size 0.188 lbs Per Sheet 0.188 lbs 0.188  
  Mat 60x120 Thick 60x120 Size 60x120 lbs Per Sheet 60x120 lbs 60x120 
  Mat 383 Thick 383 Size 383 lbs Per Sheet 383 lbs 383    
  Mat 0.41 Thick 0.41 Size 0.41 lbs Per Sheet 0.41 lbs 0.41   
  
  Row org.apache.poi.hssf.usermodel.HSSFRow@2a
  Mat 25060120 Thick 25060120 Size 25060120 lbs Per Sheet 25060120 lbs 25060120   
  Mat 0.25 Thick 0.25 Size 0.25 lbs Per Sheet 0.25 lbs 0.25   
  Mat 60x120 Thick 60x120 Size 60x120 lbs Per Sheet 60x120 lbs 60x120 
  Mat 510 Thick 510 Size 510 lbs Per Sheet 510 lbs 510    
  Mat 0.41 Thick 0.41 Size 0.41 lbs Per Sheet 0.41 lbs 0.41   
  
  Row org.apache.poi.hssf.usermodel.HSSFRow@2a
  Mat 25072144 Thick 25072144 Size 25072144 lbs Per Sheet 25072144 lbs 25072144   
  Mat 0.25 Thick 0.25 Size 0.25 lbs Per Sheet 0.25 lbs 0.25   
  Mat 72x144 Thick 72x144 Size 72x144 lbs Per Sheet 72x144 lbs 72x144 
  Mat 734.4 Thick 734.4 Size 734.4 lbs Per Sheet 734.4 lbs 734.4  
  Mat 0.41 Thick 0.41 Size 0.41 lbs Per Sheet 0.41 lbs 0.41   
  
  Row org.apache.poi.hssf.usermodel.HSSFRow@2a
  Mat 31360120 Thick 31360120 Size 31360120 lbs Per Sheet 31360120 lbs 31360120   
  Mat 0.313 Thick 0.313 Size 0.313 lbs Per Sheet 0.313 lbs 0.313  
  Mat 60x120 Thick 60x120 Size 60x120 lbs Per Sheet 60x120 lbs 60x120 
  Mat 633.2616 Thick 633.2616 Size 633.2616 lbs Per Sheet 633.2616 lbs 633.2616   
  Mat 0.41 Thick 0.41 Size 0.41 lbs Per Sheet 0.41 lbs 0.41   
  
  Row org.apache.poi.hssf.usermodel.HSSFRow@2a
  Mat 37560120 Thick 37560120 Size 37560120 lbs Per Sheet 37560120 lbs 37560120   
  Mat 0.375 Thick 0.375 Size 0.375 lbs Per Sheet 0.375 lbs 0.375  
  Mat 60x120 Thick 60x120 Size 60x120 lbs Per Sheet 60x120 lbs 60x120 
  Mat 758.7 Thick 758.7 Size 758.7 lbs Per Sheet 758.7 lbs 758.7  
  Mat 0.41 Thick 0.41 Size 0.41 lbs Per Sheet 0.41 lbs 0.41   
  
  Row org.apache.poi.hssf.usermodel.HSSFRow@2a
  Mat 50060120 Thick 50060120 Size 50060120 lbs Per Sheet 50060120 lbs 50060120   
  Mat 0.5 Thick 0.5 Size 0.5 lbs Per Sheet 0.5 lbs 0.5    
  Mat 60x120 Thick 60x120 Size 60x120 lbs Per Sheet 60x120 lbs 60x120 
  Mat 1011.6 Thick 1011.6 Size 1011.6 lbs Per Sheet 1011.6 lbs 1011.6 
  Mat 0.41 Thick 0.41 Size 0.41 lbs Per Sheet 0.41 lbs 0.41   
  
  Row org.apache.poi.hssf.usermodel.HSSFRow@2a
  Mat 75060120 Thick 75060120 Size 75060120 lbs Per Sheet 75060120 lbs 75060120   
  Mat 0.75 Thick 0.75 Size 0.75 lbs Per Sheet 0.75 lbs 0.75   
  Mat 60x120 Thick 60x120 Size 60x120 lbs Per Sheet 60x120 lbs 60x120 
  Mat 1517.4 Thick 1517.4 Size 1517.4 lbs Per Sheet 1517.4 lbs 1517.4 
  Mat 0.41 Thick 0.41 Size 0.41 lbs Per Sheet 0.41 lbs 0.41   
  
  Row org.apache.poi.hssf.usermodel.HSSFRow@2a
  Mat 10060120 Thick 10060120 Size 10060120 lbs Per Sheet 10060120 lbs 10060120   
  Mat 1 Thick 1 Size 1 lbs Per Sheet 1 lbs 1  
  Mat 60x120 Thick 60x120 Size 60x120 lbs Per Sheet 60x120 lbs 60x120 
  Mat 2023.2 Thick 2023.2 Size 2023.2 lbs Per Sheet 2023.2 lbs 2023.2 
  Mat 0.41 Thick 0.41 Size 0.41 lbs Per Sheet 0.41 lbs 0.41   
  </code></pre>
  
  <p>Excel File</p>
  
  <pre class="lang-none prettyprint-override"><code>11960120        0.119   60x120  250.00   $0.4100 
  18860120        0.188   60x120  383.00   $0.4100 
  25060120        0.250   60x120  510.00   $0.4100 
  25072144        0.250   72x144  734.40   $0.4100 
  31360120        0.313   60x120  633.26   $0.4100 
  37560120        0.375   60x120  758.70   $0.4100 
  50060120        0.500   60x120  1011.60  $0.4100 
  75060120        0.750   60x120  1517.40  $0.4100 
  10060120        1.000   60x120  2023.20  $0.4100 
  </code></pre>
  
  <p>I would like to read the above excel file much like a two dimensional array. For example:</p>
  
  <pre><code>array[0][0] = 11960120; array[0][1] = 0.119; array[0][2]= "60x120";
  </code></pre>
  
  <p>If I could just read the row and columns like the above use getter and setters from the Items class then simply place the "Item" into a map and wrap it with the item number, for example 11960120 is in cell [0][0] in the above excel example.</p>
  
  <p>To be more clear I want to read the excel file like this</p>
  
  <pre><code>11960120    0.119   60x120  250.00   $0.4100 
  </code></pre>
  
  <p>then read the next line </p>
  
  <pre><code>18860120    0.188   60x120  383.00   $0.4100
  </code></pre>
  
  <p>Each cell will be set into the Items class.</p>