Hi Amanda,
Thank you very much for your interest in Syncfusion Products.
The code that you specified in the update (i.e.)
cell.Worksheet.Columns[ColumnIndex - 1].ColumnWidth
indicates the column width of one of the columns in the worksheet whose value is specified as index. So, if there are 3 columns used in the worksheet and the ColumnIndex is specified as 5 means, then the above code will take the 4th column of the columns that has not been present in the worksheet which will throw exception.
So, if you want to check the column width of the particular cell, you can use directly the below code (i.e)
//The width of the column having the specified cell value is checked
if (cell.Value.Length > cell.ColumnWidth)
{
cell.ColumnWidth = cell.Value.Length;
}
which will set the column width to the length of the value in that cell.
For your reference, we have attached the sample below. Please try the sample from the link and let us know if this helps you.
Sample Link:
http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=ColumnWidthSample_99056-15554609.zipPlease let us know if you need any further assistance.
Thanks,
Pauline Bosco