Set cell width to text length

Hi,
Is there a way to set the column width of cells to the length of the text within the cells?
I am copying a portion of sheet from one to another but it does not maintain the cell width when I use IRange copyTo method? Is there a way this can be handled?

Thanks a lot

GE

1 Reply

MW Melba Winshia Syncfusion Team April 12, 2007 10:11 AM UTC

Hi Emperor,

Yes, it is possible to set the column width of cells to the length of the text within the cells by using AutofitColumns. By using this property we can auto Size the width of a cell according to its content. Please use the following code snippet to achieve this:

[C#]

// Autofit Columns
sheet.Range["A1:B1"].AutofitColumns();

Here is the sample for your reference:

http://websamples.syncfusion.com/samples/XlsIO.Web/4.4.0.51/59311/main.htm

Kindly let me know if you have any other questions.

Thanks,
Melba

Loader.
Up arrow icon