79449439

Date: 2025-02-18 19:58:15
Score: 0.5
Natty:
Report link

Here is my final piece of code if someone needs it. It also extends the width of the column a little bit after Autofit.

        int i = 1;
        while (i <= ws.UsedRange.Columns.Count)
        {
            try
            {
                ws.Columns[i].AutoFit();                
            }
            catch
            {
                try
                {
                    ws.Columns[i].AutoFit();
                    ws.Columns[i].ColumnWidth = ws.Columns[i].ColumnWidth + 5;                     
                }
                catch
                {
                    ws.Columns[i].Width = 255;                       
                }
            }
            i++;
        }
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: A B