Changing AutoFitWidth for Spreadsheet

1 Answer 114 Views
Spreadsheet
Ian
Top achievements
Rank 2
Bronze
Iron
Iron
Ian asked on 12 Jan 2023, 10:01 AM

Does anyone know if it's possible to change the behaviour of the Spreadsheet column 'autoFitWidth' method?

It does exactly what it says, and changes the column width to fit the contents of the column. My problem is that it's TOO good, and everything looks a bit squashed:

What I would like is to add a bit extra to the columns :

I think it just looks a bit more friendly.

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 13 Jan 2023, 10:40 AM

Hello Ian,

You can use the following approach to achieve this: 

for (int i = 0; i < worksheet.UsedCellRange.ColumnCount; i++)
{
    var col = worksheet.Columns[i];
    col.AutoFitWidth();
    double width = col.GetWidth().Value.Value;
    col.SetWidth(new ColumnWidth(width + 100, true));
}

I hope this helps. Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Spreadsheet
Asked by
Ian
Top achievements
Rank 2
Bronze
Iron
Iron
Answers by
Dimitar
Telerik team
Share this question
or