title: How to read empty cells of an excel file using POI
body: <p>I have tried to read an excel file using POI and then I wanted to put that data into a <code>JTable</code>.</p>
  
  <p>Here is the excel file,</p>
  
  <p><img src="https://i.stack.imgur.com/24nSi.png" alt="enter image description here"></p>
  
  <p>As you can see, there are two empty cells in the above table, once I read above data into a <code>JTable</code> I got following result,</p>
  
  <p><img src="https://i.stack.imgur.com/6YRkk.png" alt="enter image description here"></p>
  
  <p>In my <code>JTable</code>, empty cells has moved to a wrong place, I used following codes to get this result please assist me to achieve the correct result,</p>
  
  <pre><code>private XLSContainer xLSContainer;
      Vector cellVectorHolder;
      private int noOfCells=0;
  
      public XLSContainer readXLS(XLSFile xLSFile) {
          cellVectorHolder = new Vector();
  
          try {
  
              FileInputStream inputStream = new FileInputStream(xLSFile.getFileName());
  
              POIFSFileSystem pOIFSFileSystem = new POIFSFileSystem(inputStream);
  
              HSSFWorkbook hSSFWorkbook = new HSSFWorkbook(pOIFSFileSystem);
  
              HSSFSheet hSSFSheet = hSSFWorkbook.getSheetAt(0);
  
              Iterator rowIter = hSSFSheet.rowIterator();
  
  
              while (rowIter.hasNext()) {
                  HSSFRow row = (HSSFRow) rowIter.next();
                  if(row.getRowNum()==0){
                      noOfCells = row.getLastCellNum();
                  }
                  Iterator cellIter = row.cellIterator();
  
                  Vector cellStoreVector = new Vector();
  
                  while (cellIter.hasNext()) {
                      HSSFCell hSSFCell = (HSSFCell) cellIter.next();
                      //System.out.println(hSSFCell.getCellNum());
                      cellStoreVector.addElement(hSSFCell);
                  }
                  cellVectorHolder.addElement(cellStoreVector);
  
              }
          } catch (Exception e) {
              e.printStackTrace();
          }
          feedXLSContainer();
          return xLSContainer;
      }//readXLS
  
      private void feedXLSContainer() {
  
          xLSContainer = new XLSContainer();
  
  
          for (int i = 0; i &lt; cellVectorHolder.size(); i++) {
              Vector cellStoreVector = (Vector) cellVectorHolder.elementAt(i);
              Vector item = new Vector();
              for (int j = 0; j &lt; cellStoreVector.size(); j++) {
                  HSSFCell cell = (HSSFCell) cellStoreVector.elementAt(j);
                  item.add(cell.toString());
              }
              if (i == 0) {
                  xLSContainer.addHeader(item);
              } else {
                  xLSContainer.addRow(item);
              }
  
          }
  
      }
  </code></pre>
  
  <p>What I have done above is put headings and data rows into separate vectors in a class called <code>xLSContainer</code> and then put those vectors into a <code>JTable</code>.</p>
  
  <p>Here is how I've solved it after more google searches :-)</p>
  
  <pre><code>private XLSContainer xLSContainer;
  
      public XLSContainer readXLS(XLSFile xLSFile) {
          try {
  
              WorkbookSettings ws = new WorkbookSettings();
              ws.setLocale(new Locale("en", "EN"));
              Workbook workbook = Workbook.getWorkbook(new File(xLSFile.getFileName()), ws);
              Sheet s = workbook.getSheet(0);
              System.out.println("Sheet Content::" + s.getName());
              readDataSheet(s);
              workbook.close();
  
          } catch (Exception e) {
              e.printStackTrace();
          }
          return xLSContainer;
  
      }
  
      private void readDataSheet(Sheet s) {
          xLSContainer = new XLSContainer();
  
          int noOfRows = s.getRows();
          int noOfCols = s.getColumns();
  
  
  
          for (int i = 0; i &lt; noOfRows; i++) {
              Vector item = new Vector();
              for (int j = 0; j &lt; noOfCols; j++) {
  
                  if (s.getCell(j, i).getContents() == "") {
                      item.add("");
  
                  } else {
                      item.add(s.getCell(j, i).getContents());
  
                  }
              }
  
              if (i == 0) {
                  xLSContainer.addHeader(item);
              }else{
                  xLSContainer.addRow(item);
              }
          }
      }
  </code></pre>