title: Workbook cell style in POI/NPOI doesn't work properly with multiple styles in workbook
body: <p>I'm running into strange problem with .Net version of POI library for Excel Spreadsheets. I'm rewriting from text files to Excel 97-2003 documents and I'm like to add some formatting programmatically depend on some values gather at the begging of the program. </p>
  
  <p>At the beginning, in the same method where I was creating a new cell from given value I was creating also a new Workbook CellStyle which was wrong, because I was running out of the styles very quickly (or I was just thought it was the cause of the problem).</p>
  
  <p>Constructor of the class responsible for Excel Workbook:</p>
  
  <pre><code>public OldExcelWriter(TextWriter logger) : base(logger)
  {
      _workbook = new HSSFWorkbook();
      _sheetData = _workbook.CreateSheet("sheet1");
      _creationHelper = _workbook.GetCreationHelper();
  }
  </code></pre>
  
  <p>Method that is calling all the chains of operations:</p>
  
  <pre><code>public void Write(string path, Data data)
  {
      FillSpreadSheetWithData(data, _sheetData);
      SaveSpreadSheet(_workbook, path);
  }
  </code></pre>
  
  <p>Long story short, in FillSpreadSheetWithData I have method for creating a row inside which I'm have a loop for each cell, so basically I'm iterating thru every column, passing IRow references to a row, column value, index and formatting information like this:</p>
  
  <pre><code>for (int j = 0; j &lt; column.Count; j++)
  {
      CreateCell(row, column[j], j, data.Formatting[j]);
  }
  </code></pre>
  
  <p>and while creating a new styles (for first shot I was trying to pass some date time values) I had situation like this in my rewrited Excel: <a href="https://i.stack.imgur.com/l2Xek.png" rel="nofollow noreferrer">screenshot of excel workbook</a></p>
  
  <p>So formatting was passed correctly (also Horizontal Aligment etc.) but it get ugly after 15th row (always the same amount). </p>
  
  <pre><code>DateTime dataCell = DateTime.MaxValue;
  var cell = row.CreateCell(columnIndex);
  
   _cellStyle = _workbook.CreateCellStyle();
  
              switch (format.Type)
              {
                  case DataType.Date:
                      _cellStyle.DataFormat = _creationHelper.CreateDataFormat().GetFormat("m/dd/yyyy");
                      if (value.Replace("\n", "") != string.Empty)
                      {
                          dataCell = DateTime.ParseExact(value.Replace("\n", ""), "m/dd/yyyy",
                              System.Globalization.CultureInfo.InvariantCulture);
                      }
                      break;
              }
  
              switch (format.HorizontalAlignment)
              {
                  case Enums.HorizontalAlignment.Left:
                      _cellStyle.Alignment = HorizontalAlignment.LEFT;
                      break;
                  case Enums.HorizontalAlignment.Center:
                      _cellStyle.Alignment = HorizontalAlignment.CENTER;
                      break;
              }
  
              if (dataCell != DateTime.MaxValue)
              {
                  cell.CellStyle = _cellStyle;
                  cell.SetCellValue(dataCell);
                  dataCell = DateTime.MaxValue;
              }
              else
              {
                  cell.CellStyle = _cellStyle;
                  cell.SetCellValue(value);
              }
  </code></pre>
  
  <p>(It's not the cleanest code but I will don refactor after getting this work).</p>
  
  <p>After running into this issue I thought that maybe I will create _cellStyle variable in the constructor and only change it's value depends on the case, because it's assigned to the new cell anyway and I see while debugging that object values are correct.</p>
  
  <p>But after creating everything, it won't get any better. Styles was override by the last value of the style, and dates are spoiled also, but later: <a href="https://i.stack.imgur.com/6V7xD.png" rel="nofollow noreferrer">screnshoot of excel workbook after creating one instance of cell style</a></p>
  
  <p>I'm running out of ideas, maybe I should create every combination of the cell styles (I'm using only few data formats and alignments) but before I will do that (because I'm running out of easy options right now) I wonder what you guys think that should be done here.</p>
  
  <p><a href="https://i.stack.imgur.com/xecXS.png" rel="nofollow noreferrer">cell format is set to custom with date type</a></p>