title: Align text center in the merged region in excel using apache poi in java
body: <p>I have created an excel sheet, where I am inserting the value to cell and merging cells vertically at the same time and I am able to achieve that but the problem is that, I am not able to align text vertically center in the merged cell.Currently, text is showing at the bottom of vertically merged cell.</p>
  
  <p>here's my code,</p>
  
  <pre><code>    CellStyle cs = null;
      cs = wb.createCellStyle();
      cs.setWrapText(true);
      //cs.setAlignment(CellStyle.ALIGN_CENTER);
      cs.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
      cs.setFont(f);
  
  
  
              Row row[]=new Row[pageListAcrToDept.size()]; 
              for (int i = 0; i &lt; pageListAcrToDept.size(); i++) {
                  rowIndex = 8 + i ;
                  row[i]=sheet.createRow(rowIndex);
              }
  
              List&lt;List&lt;String&gt;&gt; datas=new ArrayList&lt;&gt;();
              datas.add(pageListAcrToDept);
              datas.add(notesListAcrToDept);
              datas.add(treatmentListAcrToDept);
              datas.add(upcListAcrToDept);
              datas.add(itemCodeListAcrToDept);
              datas.add(descListAcrToDept);
              datas.add(subDeptListAcrToDept);
              datas.add(limitListAcrToDept);
              datas.add(XforListAcrToDept);
              datas.add(priceListAcrToDept);
              datas.add(couponListAcrToDept);
              datas.add(adzoneListAcrToDept);
              datas.add(promoDescListAcrToDept);
  
              for (int column = 0; column &lt; 13; column++) {
                  List &lt;String&gt; list=datas.get(column);
              int index=0;
              for (int i = 0, prev = -1; i &lt; list.size(); i++) {
                  if (i == list.size() - 1 || ! list.get(i).equals(list.get(i + 1))) {
                      //System.out.printf("number: %d, count: %d%n", list.get(i), i - prev);
  
  
                      for(int pos=0;pos&lt;i - prev;pos++){
                          int posi=index+pos;
                      Cell cell=  row[posi].createCell(column);
                      cell.setCellStyle((CellStyle) cs);
                      cell.setCellValue(list.get(i));
                      }
                      int startrowpos=index+8;
                      int endrowpos=index+8+(i - prev)-1;
                      if(startrowpos==endrowpos){
                          LOG.info("don't merge");
                      }else{
                      CellRangeAddress cellRangeAddress = new CellRangeAddress(startrowpos, endrowpos,
                              column, column);
                      sheet.addMergedRegion(cellRangeAddress);
                      }
                      index=index+(i - prev);
                      prev = i;
                  }
              }
          }
  </code></pre>