title: How to color Excel Headers cells using Apache POI?
body: <p>I am using Apache POI to create an excel file. I am using short hand notation to create cells and I want to know if there is a way to fill the colors on the cells using the same coding pattern. </p>
  
  <p>Coding standard 1.</p>
  
  <pre><code>Row headerRow = sheet.createRow(0);
   headerRow.createCell(0).setCellValue(NYPG3Constants.FIRST_NAME);
   headerRow.createCell(1).setCellValue(NYPG3Constants.LAST_NAME);
   headerRow.createCell(2).setCellValue(NYPG3Constants.POLICY_NUMBER);
   headerRow.createCell(3).setCellValue(NYPG3Constants.ZIP_CODE);
   headerRow.createCell(4).setCellValue(NYPG3Constants.DATE_OF_BIRTH);
  </code></pre>
  
  <p>I can set styles using following coding pattern but for every cell headers I need to create a separate cell object. </p>
  
  <p>Coding standard 2</p>
  
  <pre><code>CellStyle style = workBook.createCellStyle();
   style.setFillForegroundColor(HSSFColor.GOLD.index);
   style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
  
   Cell cell = headerRow.createCell(0);
   cell.setCellValue(NYPG3Constants.FIRST_NAME);
   cell.setCellStyle(style);
  </code></pre>
  
  <p>Is there a way to fill colors on the header cells using my first coding standard?</p>
  
  <p>Thanks in advance</p>