title: Apache POI: Cell / Row Style setting does not work
body: <p>I have a workbook with several Sheets containing data.</p>
  
  <p>Requirements:</p>
  
  <p>1) top row bold
  2) all cells top and left aligned
  3) Column size fits to <strong>top row cell value</strong></p>
  
  <p>I use the following code. It does not throw an error or exception, the File is filled successfully. But the style is not applied. I think I have missed something:</p>
  
  <pre><code>      ... // fill Excel ..
  
        if (sheet.getPhysicalNumberOfRows() &gt; 0) {
  
          CellStyle topRowStyle = wb.createCellStyle();   // makes top row bold
          Font topRowFont = wb.createFont();              
          topRowFont.setBold(true);
          topRowStyle.setFont(topRowFont);
          sheet.getRow(0).setRowStyle(topRowStyle);
  
          CellStyle style = wb.createCellStyle();         // creates general sheet style
          Font font= wb.createFont();                     
          font.setFontHeightInPoints((short)10);
          font.setFontName("Arial");
          style.setFont(font);
          style.setAlignment(CellStyle.ALIGN_LEFT);
          style.setAlignment(CellStyle.VERTICAL_TOP);
  
          Iterator&lt;Row&gt; rowIterator = sheet.iterator();       
              while (rowIterator.hasNext()) {
                Row row = rowIterator.next();
                row.setRowStyle(style);
                int columnIndex = cell.getColumnIndex();              
              }
          }
  
             // continue with other stuff
  </code></pre>
  
  <p>In this code I tried to implement 1) and 2).
  But has anyone an idea on how to solve 3)? I earlier worked with</p>
  
  <pre><code>sheet.autoSizeColumn(columnIndex);
  </code></pre>
  
  <p>But this just autofits the columns according to the longest (by character count) value.</p>
  
  <p>Thank you!</p>