title: Java Poi XSSF - create pivot table with multiple expandable columns
body: <p>I have about 1000 rows with multiple columns and I want to create a pivot table out of them.</p>
  
  <p>My actual result is:
  <a href="https://i.stack.imgur.com/zPfkp.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zPfkp.jpg" alt="enter image description here"></a></p>
  
  <p>But I want to get a pivot table which looks like this:
  <a href="https://i.stack.imgur.com/WvovN.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WvovN.jpg" alt="enter image description here"></a></p>
  
  <p>My current code:</p>
  
  <pre><code>// ... 
  // fill sheet with data 
  // ...
  
  // create Pivot table
  int firstRow = sheet.getFirstRowNum() + firstDataRow;
  int lastRow = sheet.getLastRowNum();
  int firstCol = sheet.getRow(0).getFirstCellNum();
  int lastCol = sheet.getRow(firstRow).getLastCellNum();
  
  CellReference topLeft = new CellReference(firstRow, firstCol);
  CellReference botRight = new CellReference(lastRow, lastCol-1);
  
  XSSFPivotTable pivotTable = pivotSheet.createPivotTable(
          new AreaReference(topLeft, botRight), new CellReference(firstRow, lastCol), sheet);
  
  pivotTable.addRowLabel(lastCol - 1); // month
  pivotTable.addRowLabel(6); // car
  pivotTable.addRowLabel(lastCol - 2); // state
  pivotTable.addColumnLabel(DataConsolidateFunction.COUNT, 0, 
          resourceBundle.getString("Count"));
  </code></pre>
  
  <p>I even do not know how to name the different results.
  I think I need to go deeper into the poi subject matter to generate a more complex pivot table but I do not know how.</p>
  
  <p>Could anybody help me with this issue?</p>