title: Problematic corruption of .xlsx files with NPOI - Excel cannot open the file 'file.xlsx" because the file format or file extension is not valid
body: <p>When reading or modifying some user-created .xlsx files, I get the following error message:</p>
  
  <pre><code>We found a problem with some content in 'test.xlsx'. Do you want us to try to recover as much as we can? If you trust the source of this workbook, click Yes.
  </code></pre>
  
  <p>Clicking Yes gets me another message:</p>
  
  <pre><code>Excel cannot open the file 'test.xlsx' because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file.
  </code></pre>
  
  <p>Example of a problem .xlsx file <a href="https://ufile.io/2b349" rel="noreferrer">here</a> (before put in NPOI).</p>
  
  <p>Here's the same file, now corrupted after being read from and written back with <code>iWorkbook.Write(filestream);</code> <a href="https://ufile.io/9ac96" rel="noreferrer">here</a>.</p>
  
  <p>I have no issues creating a new .xlsx file with the following code:</p>
  
  <pre><code>string newPath = @"C:\MyPath\test.xlsx";
  
  using (FileStream fs = new FileStream(newPath, FileMode.Create, FileAccess.Write))
  {
      IWorkbook wb = new XSSFWorkbook();
      wb.CreateSheet();
      ISheet s = wb.GetSheetAt(0);
      IRow r = s.CreateRow(0);
      r.CreateCell(0);
      ICell c = r.GetCell(0);
      c.SetCellValue("test");
      wb.Write(fs);
      fs.Close();
  }
  </code></pre>
  
  <p>That works fine.</p>
  
  <p>Even opening one of the problem child .xlsx files, setting it to an IWorkbook and writing it back to the file works:</p>
  
  <pre><code>string newPath = @"C:\MyPath\test.xlsx";
  
  using (FileStream fs = new FileStream(newPath, FileMode.Open, FileAccess.ReadWrite))
  {
      IWorkbook wb = new XSSFWorkbook(fs);
      wb.Write(fs);
      fs.Close();
  }
  </code></pre>
  
  <p>However, after running through code that reads from it, gets ISheets, IRows, ICells, etc.... it corrupts the .xlsx file. <strong>Even though I specifically removed anything that modifies the workbook.</strong> No Creates, Sets, Styles, etc. with NPOI.</p>
  
  <p>I can't really include my code because it would just be confusing, but for the sake of completeness I'm really only using the following types and functions from NPOI during this test:</p>
  
  <pre><code>IWorkbook
  XSSFWorkbook
  ISheet
  IRow
  ICell
  .GetSheetAt
  .GetRow
  .GetCell
  .LastRowNum
  </code></pre>
  
  <p>So one of those causes corruption. I would like to eventually set values again and get it working like I have for .xls.</p>
  
  <p>Has anyone experienced this?  What are some NPOI functions that could cause corruption? Any input would be appreciated. </p>
  
  <p>Edit: Using NPOI v2.2.1.</p>