title: Apache POI preserve existing Excel formatting style
body: <p>I'm using Apache POI to read an existing template excel file and would like to copy the existing styles in some header rows and apply them to new cells.</p>
  
  <p>It seems like the existing formatting is not being applied (IE, Date, Currency, Percentage etc).</p>
  
  <p>The code is pretty basic:</p>
  
  <pre><code>//read existing style
  Row existingRow = sheet.getRow(headerRowIndex);
  Cell existingCell = existingRow.getCell(0);
  CellStyle currentStyle = existingCell.getCellStyle();
  
  
  //apply date style here
  Date date = StringUtil.toDate(map.get(column.getHeaderName()));
  cell.setCellValue(date);
  //apply previous style      
  cell.setCellStyle(currentStyle);
  </code></pre>
  
  <p>It does copy the font and background color etc but it seems like the formatting is lost (all cells have "general" formatting applied).</p>
  
  <p>Also when I do this:</p>
  
  <pre><code>currentStyle.getDataFormat(); // always 0
  </code></pre>
  
  <p>So it makes me think that I'm not reading the formatting correctly. Any ideas on how to accomplish this?</p>