NativeExcel2 for .Net Developer's Reference

IRange.AutofitMethod

Changes the width of the columns in the range to achieve the best fit.

[Visual Basic]
SubAutofit()
[C#]
voidAutofit();
[C++]
voidAutofit();
[JScript]
functionAutofit();

Remarks

Use Rows. Autofit method to change the height of the rows in order to achieve the best fit.

Example

This example changes the width of the columns in the used range to achieve the best fit.

[C#]
 book.Worksheets[1].UsedRange.Autofit();
[VisualBasic]
 book.Worksheets(1).UsedRange.Autofit()
[C++]
 book->Worksheets->Item[1]->UsedRange->Autofit();

See Also

IRange Interface | NativeExcel Namespace | IRangeRows.Autofit Method | UsedRange Property