title: NPOI Auto resize column
body: <p>I am trying to write some contents to excel file using NPOI. But while using the auto resize column method is causing a error "Parameter not valid". This happens only for sheets with huge data. Below is code which I used to do the job.</p>
  
  <pre><code>public void CloseDatabaseLogFile()
  {
      try
      {
          FileStream sw = File.Create(excelSheetPath);
  
          oSheet.AutoSizeColumn(0);
          oSheet.SetColumnWidth(1, 8400);
  
          oSheet.AutoSizeColumn(2);
          oSheet.AutoSizeColumn(3);
          oSheet.AutoSizeColumn(4);
          oSheet.AutoSizeColumn(5);
          oSheet.AutoSizeColumn(6);
          oSheet.AutoSizeColumn(7);
          oSheet.AutoSizeColumn(8);
          oSheet.AutoSizeColumn(9);
          oSheet.AutoSizeColumn(10);
  
          workbook.Write(sw);
          sw.Close();
      }
      catch (Exception e)
      {
          throw e;
      }
  }
  </code></pre>