title: Autofit long strings with EPPLus
body: <p>Using EPPLus library, I'm trying to autofit very long strings in xlsx cells this way:</p>
  
  <pre><code>worksheet.Cells.AutoFitColumns();
  </code></pre>
  
  <p>Rows: 1000</p>
  
  <p>Columns: 10</p>
  
  <p>For 2 columns, I'm expecting around 6000 character in each cell.
  In this scenario, AutoFitColumns method generates the following exception:</p>
  
  <blockquote>
    <p><strong>Message</strong>: A generic error occurred in GDI+. </p>
    
    <p><strong>StackTrace</strong>:    at
    System.Drawing.Graphics.MeasureString(String text, Font font, SizeF
    layoutArea, StringFormat stringFormat)    at
    System.Drawing.Graphics.MeasureString(String text, Font font, Int32
    width, StringFormat format)    at
    OfficeOpenXml.ExcelRangeBase.AutoFitColumns(Double MinimumWidth,
    Double MaximumWidth)    at
    OfficeOpenXml.ExcelRangeBase.AutoFitColumns()...</p>
  </blockquote>
  
  <p><strong>EDIT</strong></p>
  
  <p>Here is my full code:</p>
  
  <pre><code>using (ExcelPackage package = new ExcelPackage(newFile))
  {
      ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Sheet1");
      // Setup the first row with headers
      for (int j = 0; j &lt; fields.Length; j++)
      {
          worksheet.Cells[1, j + 1].Value = fields[j];
      }
  
      Color colFromHex = ColorTranslator.FromHtml("#B4B4B4");
      worksheet.Row(1).Style.Fill.PatternType = ExcelFillStyle.Solid;
      worksheet.Row(1).Style.Fill.BackgroundColor.SetColor(colFromHex);
  
  
      // Insert new rows
      for (int i = 0; i &lt; elements.Count; i++)
      {
          // this will return List&lt;object&gt;
          var properties =  elements[i].GetPatentProperties();
          for (int j = 0; j &lt; properties.Count; j++)
          {
              worksheet.Cells[i + 2, j + 1].Value = properties[j];
          }
      }
  
      // This will throw an exception for big number of elements: ~ 1000 element
      worksheet.Cells.AutoFitColumns();
      worksheet.Cells.Style.WrapText = true;
  
      //worksheet.Cells[autosize].Style.HorizontalAlignment = ExcelHorizontalAlignment.CenterContinuous;
      package.Save();
  }
  </code></pre>
  
  <p>Note that for the same list of elements, if I remove <code>worksheet.Cells.AutoFitColumns();</code>, I will get my xlsx file without exception.</p>
  
  <p>Is it possible to overcome this issue?</p>