title: Which is a good strategy to read a formatted excel file in java to put it latter in a JSON format?
body: <p>I need to think about a strategy to read data stored in an excel sheet formatted so that it can be delivered in JSON format, as long as they keep original headings.</p>
  
  <p>But since the headers are complex that is my biggest problem; how to handle them, I can't think of a good strategy to put them as expected in the output. here is the real excel file I need to decompose: <a href="https://github.com/EEsparaquia/readFormattedExcel/blob/master/Book1.xlsx" rel="nofollow noreferrer">https://github.com/EEsparaquia/readFormattedExcel/blob/master/Book1.xlsx</a></p>
  
  <pre><code>-------------------------------------------------------------------
  Order002                    |       |                             | 
  -------------------------------------------------------------------
  02X Phones                  |       |                             |
                                      -------------------------------
                              |       |   Order condition           |
  -------------------------------------------------------------------
                              |       |                             |
  -------------------------------------------------------------------
  order | Date | Group | Desc | Comm- | Order | Type | Sub Condition|
    #   |      |       |      |  ents | Type  |      |--------------|
        |      |       |      |       |       |      | Blue  |  Red |
  -------------------------------------------------------------------
    1   |12119 |   A   | 5.9  |  New  |  D40  |  2   |   90  |   2  |
        |      |       | Inch |       |       |      |       |      |
  -------------------------------------------------------------------
    2   |12119 |   A   | 5.9  |  New  |  D40  |  2   |   87  |   3  |
        |      |       | Inch |       |       |      |       |      |
  </code></pre>
  
  <hr>
  
  <p>And my output should be in JSON format:</p>
  
  <pre><code>{
   "Order002":{
     "02X Phones":{
       "Order #":"1",
       "Date":"12119",
       "Group":"A",
       "Desc":"5.9 Inch",
       "Comments":"New",
       "Order Conditions":{
        "Order Type":"D40",
        "Type":"2",
        "Sub Condition":{
         "Blue":"90",
         "Red":"2"
        }
       }
      }
     }
    }
  </code></pre>
  
  <p>So far I am able to read the excel sheet data line by line and column by column, that is, first I read cell [1, A], [1, B], [1, C] ... [1, "n"] and after [2, A], [2, B], [2, C] ... [2, "n"].</p>
  
  <p>Here is my code so far:</p>
  
  <pre><code>import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
  import org.apache.poi.ss.usermodel.*;
  
  import javax.xml.bind.annotation.XmlType;
  import java.io.File;
  import java.io.IOException;
  import java.util.Iterator;
  
  public class App {
  
     public static final String SAMPLE_XLSX_FILE_PATH = "Book1.xlsx";
  
     public static void main(String []args){
  
      try {
          //Creating a workbook from Excel file
          Workbook workbook = WorkbookFactory.create(new File(SAMPLE_XLSX_FILE_PATH));
  
          //Getting the Sheet at index zero
          Sheet sheet = workbook.getSheetAt(0);
  
          DataFormatter dataFormatter= new DataFormatter();
  
          System.out.println("\n\nIterating over Rows and Columns using Java 8 forEach with lambda\n");
  
          sheet.forEach(row -&gt; {
              row.forEach(cell -&gt; {
                  printCellValue(cell);
  
              });
              System.out.println("End of forEach - Lambda");
           });
  
  
          workbook.close();
      } catch (IOException e) {
          e.printStackTrace();
      } catch (InvalidFormatException e) {
          e.printStackTrace();
      }
    }
  
    private static void printCellValue(Cell cell){
      switch (cell.getCellTypeEnum()){
          case BOOLEAN:
              System.out.println(cell.getBooleanCellValue());
              break;
          case STRING:
              System.out.println(cell.getStringCellValue());
              break;
          case NUMERIC:
              if (DateUtil.isCellDateFormatted(cell))
                  System.out.println(cell.getDateCellValue());
              else
                  System.out.println(cell.getNumericCellValue());
              break;
          case FORMULA:
              System.out.println(cell.getCellFormula());
              break;
          case BLANK:
              System.out.println("");
              break;
          default:
              System.out.println("");
      }
      System.out.println("\t");
     }
   }
  </code></pre>